Example #1
0
 public void RefreshConditionButtons(FilterConditionsViewModel filter = null, bool isRootFilter = true, bool processJoins = true, JoinsViewModel joins = null)
 {
     joins = joins ?? Joins;
     if (filter == null)
     {
         DeleteSelectedConditionsButton.IsVisible = false;
         GroupSelectedConditionsAnd.IsVisible     = false;
         GroupSelectedConditionsOr.IsVisible      = false;
         UngroupSelectedConditions.IsVisible      = false;
         filter = FilterConditions;
         if (!AllowQuery)
         {
             return;
         }
     }
     if (filter != null)
     {
         var selectedCount = filter.SelectedConditions.Count();
         if (selectedCount > 0)
         {
             DeleteSelectedConditionsButton.IsVisible = true;
         }
         if (selectedCount > 0 && !isRootFilter)
         {
             UngroupSelectedConditions.IsVisible = true;
         }
         if (selectedCount > 1 && filter.FilterOperator == FilterOperator.And)
         {
             GroupSelectedConditionsOr.IsVisible = true;
         }
         if (selectedCount > 1 && filter.FilterOperator == FilterOperator.Or)
         {
             GroupSelectedConditionsAnd.IsVisible = true;
         }
         foreach (var item in filter.FilterConditions)
         {
             RefreshConditionButtons(item, isRootFilter: false, processJoins: false);
         }
         if (processJoins && joins != null && joins.Joins != null)
         {
             foreach (var join in joins.Joins)
             {
                 if (join.FilterConditions != null)
                 {
                     RefreshConditionButtons(join.FilterConditions, isRootFilter: true, processJoins: join.Joins != null, joins: join.Joins);
                 }
             }
         }
     }
 }
        public void DeleteSelected(FilterConditionsViewModel parentFilterConditions)
        {
            var isRootFilter = parentFilterConditions == null;

            foreach (var item in Conditions.Where(c => c.QueryConditionObject.IsSelected).ToArray())
            {
                Conditions.Remove(item);
            }
            foreach (var item in FilterConditions.ToArray())
            {
                item.DeleteSelected(this);
            }
            CheckRemoveFilter(parentFilterConditions);
        }
        public void UnGroupSelected(FilterConditionsViewModel parentFilterConditions)
        {
            var isRootFilter       = parentFilterConditions == null;
            var selectedConditions = SelectedConditions;

            if (selectedConditions.Count() > 0 &&
                parentFilterConditions != null)
            {
                foreach (var item in selectedConditions)
                {
                    Conditions.Remove(item);
                    parentFilterConditions.Conditions.Insert(0, item);
                }
            }
            foreach (var item in FilterConditions.ToArray())
            {
                item.UnGroupSelected(this);
            }
            CheckRemoveFilter(parentFilterConditions);
        }
        public void RefreshConditionButtons(FilterConditionsViewModel filter = null)
        {
            var isRootFilter = filter == null;

            if (filter == null)
            {
                DeleteSelectedConditionsButton.IsVisible = false;
                GroupSelectedConditionsAnd.IsVisible     = false;
                GroupSelectedConditionsOr.IsVisible      = false;
                UngroupSelectedConditions.IsVisible      = false;
                filter = FilterConditions;
                if (!AllowQuery)
                {
                    return;
                }
            }
            if (filter != null)
            {
                var selectedCount = filter.SelectedConditions.Count();
                if (selectedCount > 0)
                {
                    DeleteSelectedConditionsButton.IsVisible = true;
                }
                if (selectedCount > 0 && !isRootFilter)
                {
                    UngroupSelectedConditions.IsVisible = true;
                }
                if (selectedCount > 1 && filter.FilterOperator == FilterOperator.And)
                {
                    GroupSelectedConditionsOr.IsVisible = true;
                }
                if (selectedCount > 1 && filter.FilterOperator == FilterOperator.Or)
                {
                    GroupSelectedConditionsAnd.IsVisible = true;
                }
                foreach (var item in filter.FilterConditions)
                {
                    RefreshConditionButtons(item);
                }
            }
        }
        public void GroupSelected(FilterOperator filterOperator, FilterConditionsViewModel parentFilterConditions = null)
        {
            var isRootFilter       = parentFilterConditions == null;
            var selectedConditions = SelectedConditions;

            if (selectedConditions.Count() > 1 &&
                FilterOperator != filterOperator)
            {
                var newFilterCondition = CreateFilterCondition();
                newFilterCondition.FilterOperator = filterOperator;
                foreach (var item in selectedConditions)
                {
                    Conditions.Remove(item);
                    newFilterCondition.Conditions.Insert(0, item);
                }
                FilterConditions.Add(newFilterCondition);
            }
            foreach (var item in FilterConditions.ToArray())
            {
                item.GroupSelected(filterOperator, this);
            }
        }
        private void DeleteSelected(FilterConditionsViewModel filterConditions = null, FilterConditionsViewModel parentFilterConditions = null)
        {
            var isRootFilter = filterConditions == null;

            if (filterConditions == null)
            {
                filterConditions = FilterConditions;
            }
            var selectedConditions = filterConditions.SelectedConditions;

            foreach (var item in filterConditions.Conditions.Where(c => c.QueryConditionObject.IsSelected).ToArray())
            {
                filterConditions.Conditions.Remove(item);
            }
            foreach (var item in filterConditions.FilterConditions.ToArray())
            {
                DeleteSelected(item, filterConditions);
            }
            CheckRemoveFilter(filterConditions, parentFilterConditions);
            if (isRootFilter)
            {
                RefreshConditionButtons();
            }
        }
 private static void CheckRemoveFilter(FilterConditionsViewModel filterConditions, FilterConditionsViewModel parentFilterConditions)
 {
     if (filterConditions.Conditions.Count == 1 &&
         filterConditions.FilterConditions.Count == 0 &&
         parentFilterConditions != null)
     {
         parentFilterConditions.FilterConditions.Remove(filterConditions);
     }
 }
 private void UnGroupSelected(FilterConditionsViewModel filterConditions = null, FilterConditionsViewModel parentFilterConditions = null)
 {
     FilterConditions?.UnGroupSelected(null);
     if (Joins != null && Joins.Joins != null)
     {
         foreach (var join in Joins.Joins)
         {
             join.UngroupSelectedConditions();
         }
     }
     RefreshConditionButtons();
 }
        private void UnGroupSelected(FilterConditionsViewModel filterConditions = null, FilterConditionsViewModel parentFilterConditions = null)
        {
            var isRootFilter = filterConditions == null;

            if (filterConditions == null)
            {
                filterConditions = FilterConditions;
            }
            var selectedConditions = filterConditions.SelectedConditions;

            if (selectedConditions.Count() > 0 &&
                parentFilterConditions != null)
            {
                foreach (var item in selectedConditions)
                {
                    filterConditions.Conditions.Remove(item);
                    parentFilterConditions.Conditions.Insert(0, item);
                }
            }
            foreach (var item in filterConditions.FilterConditions.ToArray())
            {
                UnGroupSelected(item, filterConditions);
            }
            CheckRemoveFilter(filterConditions, parentFilterConditions);
            if (isRootFilter)
            {
                RefreshConditionButtons();
            }
        }
        private void GroupSelected(FilterOperator filterOperator, FilterConditionsViewModel filterConditions = null, FilterConditionsViewModel parentFilterConditions = null)
        {
            var isRootFilter = filterConditions == null;

            if (filterConditions == null)
            {
                filterConditions = FilterConditions;
            }
            var selectedConditions = filterConditions.SelectedConditions;

            if (selectedConditions.Count() > 1 &&
                filterConditions.FilterOperator != filterOperator)
            {
                var newFilterCondition = CreateFilterCondition();
                newFilterCondition.FilterOperator = filterOperator;
                foreach (var item in selectedConditions)
                {
                    filterConditions.Conditions.Remove(item);
                    newFilterCondition.Conditions.Insert(0, item);
                }
                filterConditions.FilterConditions.Add(newFilterCondition);
            }
            foreach (var item in filterConditions.FilterConditions.ToArray())
            {
                GroupSelected(filterOperator, item, filterConditions);
            }
            if (isRootFilter)
            {
                RefreshConditionButtons();
            }
        }