public FilterConditionWindow(FilterConditionViewModel condition)
 {
     InitializeComponent();
     conditionViewModel = condition;
     DataContext        = condition;
     if (condition == null || condition.FilterMode == FilterMode.Attributes)
     {
         AttributesRadioButton.IsChecked = true;
     }
     else
     {
         AreaRadioButton.IsChecked = true;
     }
 }
        internal FilterConditionViewModel CloneDeep()
        {
            var clonedViewModel = new FilterConditionViewModel(this.requiredValues);

            clonedViewModel.SelectedColumnName = SelectedColumnName;
            clonedViewModel.FilterCondition    = FilterCondition;
            clonedViewModel.FilterMode         = FilterMode;
            clonedViewModel.SelectedAreaUnit   = SelectedAreaUnit;
            clonedViewModel.IsIgnoreCase       = IsIgnoreCase;

            clonedViewModel.MatchExpression = MatchExpression;
            clonedViewModel.MatchType       = MatchType;
            clonedViewModel.FromDate        = FromDate;
            clonedViewModel.ToDate          = ToDate;
            return(clonedViewModel);
        }
        private void InitializeConditions(Collection <FilterCondition> conditions)
        {
            foreach (var condition in conditions.Where(c => !(c is ScriptFilterCondition)))
            {
                FilterConditionViewModel itemViewModel = new FilterConditionViewModel(requiredValues, condition);
                itemViewModel.PropertyChanged += ItemViewModel_PropertyChanged;
                FilterConditions.Add(itemViewModel);
            }

            scriptFilterCondition = conditions.OfType <ScriptFilterCondition>().FirstOrDefault();
            if (scriptFilterCondition == null)
            {
                scriptFilterCondition            = new ScriptFilterCondition();
                scriptFilterCondition.ScriptType = FilterStyleScriptType;
                conditions.Add(scriptFilterCondition);
            }
        }
        private string GetFilterString(FilterConditionViewModel filterCondition)
        {
            string filter = string.Empty;

            switch (filterCondition.MatchType.Key)
            {
            case FilterConditionType.Equal:
                filter = string.Format(CultureInfo.InvariantCulture, "[{0}].ToString().ToLowerInvariant().Equals(\"{1}\")", filterCondition.FilterCondition.ColumnName, filterCondition.MatchExpression.ToLowerInvariant());
                break;

            case FilterConditionType.Contains:
                filter = string.Format(CultureInfo.InvariantCulture, "[{0}].ToString().ToLowerInvariant().Contains(\"{1}\")", filterCondition.FilterCondition.ColumnName, filterCondition.MatchExpression.ToLowerInvariant());
                break;

            case FilterConditionType.StartsWith:
                filter = string.Format(CultureInfo.InvariantCulture, "[{0}].ToString().ToLowerInvariant().StartsWith(\"{1}\")", filterCondition.FilterCondition.ColumnName, filterCondition.MatchExpression.ToLowerInvariant());
                break;

            case FilterConditionType.EndsWith:
                filter = string.Format(CultureInfo.InvariantCulture, "[{0}].ToString().ToLowerInvariant().EndsWith(\"{1}\")", filterCondition.FilterCondition.ColumnName, filterCondition.MatchExpression.ToLowerInvariant());
                break;

            case FilterConditionType.DoesNotEqual:
                filter = string.Format(CultureInfo.InvariantCulture, "![{0}].ToString().ToLowerInvariant().Equals(\"{1}\")", filterCondition.FilterCondition.ColumnName, filterCondition.MatchExpression.ToLowerInvariant());
                break;

            case FilterConditionType.DoesNotContain:
                filter = string.Format(CultureInfo.InvariantCulture, "![{0}].ToString().ToLowerInvariant().Contains(\"{1}\")", filterCondition.FilterCondition.ColumnName, filterCondition.MatchExpression.ToLowerInvariant());
                break;

            case FilterConditionType.GreaterThan:
                filter = string.Format(CultureInfo.InvariantCulture, "double.Parse([{0}].ToString()) > (double){1}", filterCondition.FilterCondition.ColumnName, filterCondition.MatchExpression);
                break;

            case FilterConditionType.GreaterThanOrEqualTo:
                filter = string.Format(CultureInfo.InvariantCulture, "double.Parse([{0}].ToString()) >= (double){1}", filterCondition.FilterCondition.ColumnName, filterCondition.MatchExpression);
                break;

            case FilterConditionType.LessThan:
                filter = string.Format(CultureInfo.InvariantCulture, "double.Parse([{0}].ToString()) < (double){1}", filterCondition.FilterCondition.ColumnName, filterCondition.MatchExpression);
                break;

            case FilterConditionType.LessThanOrEqualTo:
                filter = string.Format(CultureInfo.InvariantCulture, "double.Parse([{0}].ToString()) <= (double){1}", filterCondition.FilterCondition.ColumnName, filterCondition.MatchExpression);
                break;

            case FilterConditionType.Custom:
                break;

            case FilterConditionType.DynamicLanguage:
                break;

            case FilterConditionType.DateRange:
                break;

            case FilterConditionType.NumericRange:
                filter = string.Format(CultureInfo.InvariantCulture, "double.Parse([{0}].ToString()) <= (double){1} && double.Parse([{0}].ToString()) >= (double){2}", filterCondition.FilterCondition.ColumnName, filterCondition.ToNumberic, filterCondition.FromNumberic);
                break;

            case FilterConditionType.IsEmpty:
                filter = string.Format(CultureInfo.InvariantCulture, "String.IsEmpty({0})", filterCondition.FilterCondition.ColumnName, filterCondition.MatchExpression);
                break;

            case FilterConditionType.IsNotEmpty:
                filter = string.Format(CultureInfo.InvariantCulture, "!String.IsEmpty({0})", filterCondition.FilterCondition.ColumnName, filterCondition.MatchExpression);
                break;

            case FilterConditionType.ValidFeature:
                break;

            default:
                break;
            }

            return(filter);
        }
        private void InitializeCommands()
        {
            addConditionCommand = new RelayCommand(() =>
            {
                FilterConditionWindow newFilterConditionWindow = new FilterConditionWindow();
                FilterConditionViewModel itemViewModel         = new FilterConditionViewModel(RequiredValues);
                itemViewModel.PropertyChanged       += ItemViewModel_PropertyChanged;
                newFilterConditionWindow.DataContext = itemViewModel;
                foreach (var item in columnNameTypes)
                {
                    newFilterConditionWindow.ViewModel.ColumnNameTypes[item.Key] = item.Value;
                }

                newFilterConditionWindow.ViewModel.SelectedColumnName = newFilterConditionWindow.ViewModel.ColumnNames.FirstOrDefault();
                if (newFilterConditionWindow.ShowDialog().GetValueOrDefault())
                {
                    var stylePlugin = GisEditor.StyleManager.GetDefaultStylePlugin(requiredValues.AvailableStyleCategories);

                    filterConditions.Add(newFilterConditionWindow.ViewModel);
                    SyncConditions();
                    RaisePropertyChanged("FilterConditions");
                }
            });

            editConditionCommand = new RelayCommand <FilterConditionViewModel>(v =>
            {
                var clonedViewModel = v.CloneDeep();
                clonedViewModel.ColumnNameTypes.Clear();

                foreach (var item in columnNameTypes)
                {
                    clonedViewModel.ColumnNameTypes[item.Key] = item.Value;
                }

                FilterConditionWindow newFilterConditionWindow = new FilterConditionWindow(clonedViewModel);

                FeatureLayerPlugin resultLayerPlugin = GisEditor.LayerManager.GetLayerPlugins(RequiredValues.FeatureLayer.GetType()).LastOrDefault() as FeatureLayerPlugin;

                if (resultLayerPlugin != null)
                {
                    Collection <IntermediateColumn> columns = resultLayerPlugin.GetIntermediateColumns(requiredValues.FeatureLayer.FeatureSource);
                    foreach (var item in columns)
                    {
                        newFilterConditionWindow.ViewModel.ColumnNameTypes[item.ColumnName] = item.IntermediateColumnType;
                    }
                }

                if (newFilterConditionWindow.ShowDialog().Value)
                {
                    var index = FilterConditions.IndexOf(v);
                    if (index != -1)
                    {
                        v = clonedViewModel;
                        FilterConditions.RemoveAt(index);
                        FilterConditions.Insert(index, v);
                    }
                }

                SyncConditions();
            });

            removeConditionCommand = new RelayCommand <FilterConditionViewModel>(v =>
            {
                if (FilterConditions.Contains(v))
                {
                    var messageBoxResult = System.Windows.Forms.MessageBox.Show(GisEditor.LanguageManager.GetStringResource("FilterStyleViewModelConditionRemovedMessage")
                                                                                , "Alert"
                                                                                , System.Windows.Forms.MessageBoxButtons.YesNo);

                    if (messageBoxResult == System.Windows.Forms.DialogResult.Yes)
                    {
                        FilterConditions.Remove(v);
                        SyncConditions();
                        RaisePropertyChanged("FilterConditions");
                    }
                }
            });

            testScriptCommand = new RelayCommand(() =>
            {
                try
                {
                    var result = actualFilterStyle.GetRequiredColumnNames().All(c => requiredValues.ColumnNames.Contains(c));
                    if (!result)
                    {
                        MessageBox.Show(GisEditor.LanguageManager.GetStringResource("FilterStyleUserControlColumnMessage"));
                    }
                    else
                    {
                        Collection <Feature> features   = new Collection <Feature>();
                        ScriptFilterCondition condition = actualFilterStyle.Conditions.OfType <ScriptFilterCondition>().FirstOrDefault();
                        if (condition != null)
                        {
                            condition.GetMatchingFeatures(features);
                        }
                        MessageBox.Show(GisEditor.LanguageManager.GetStringResource("TestPassMessage"));
                    }
                }
                catch (Exception ex)
                {
                    GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                    MessageBox.Show(ex.Message);
                }
            });

            viewDataCommand = new RelayCommand(() =>
            {
                DataViewerUserControl content = new DataViewerUserControl();
                content.ShowDialog();
            });

            showResultsCommand = new ObservedCommand(() =>
            {
                ShowFilteredData(requiredValues.FeatureLayer, FilterConditions.Select(f => f.FilterCondition), "");
            }, () => filterConditions.Count > 0);
        }
Exemple #6
0
        public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is FilterConditionViewModel)
            {
                FilterConditionViewModel matchCondition = (FilterConditionViewModel)value;
                FilterConditionType      matchType      = matchCondition.MatchType.Key;

                //string logical = "OR";
                //if (matchCondition.Logical)
                //{
                //    logical = "AND";
                //}

                if (matchType == FilterConditionType.DynamicLanguage)
                {
                    return(matchCondition.MatchExpression);
                }
                else if (matchType == FilterConditionType.DateRange)
                {
                    string fromDateString = "\"" + matchCondition.ColumnName + "\"" + ">=" + "\"" + matchCondition.FromDate.ToString() + "\"";
                    string toDateString   = "\"" + matchCondition.ColumnName + "\"" + "<=" + "\"" + matchCondition.ToDate.ToString() + "\"";

                    string contractor = " and ";

                    if (DateTime.Parse(matchCondition.FromDate).ToShortDateString().Equals(new DateTime(1900, 1, 1).ToShortDateString()))
                    {
                        fromDateString = string.Empty;
                        contractor     = string.Empty;
                    }

                    if (DateTime.Parse(matchCondition.ToDate).ToShortDateString().Equals(DateTime.MaxValue.ToShortDateString()))
                    {
                        toDateString = string.Empty;
                        contractor   = string.Empty;
                    }

                    return(string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", fromDateString, contractor, toDateString));
                }
                else if (matchType == FilterConditionType.ValidFeature)
                {
                    return("Features are " + (matchCondition.ValidStatus ? "valid" : "invalid"));
                }
                else
                {
                    string matches = string.Empty;

                    if (FilterHelper.FilterConditionNames.ContainsKey(matchType))
                    {
                        matches = FilterHelper.FilterConditionNames[matchType];
                    }
                    else
                    {
                        matches = "unknown match";
                    }

                    if (matchType == FilterConditionType.IsNotEmpty || matchType == FilterConditionType.IsEmpty)
                    {
                        return(string.Format(CultureInfo.InvariantCulture, "\"{0}\" {1}"
                                             , matchCondition.ColumnName
                                             , matches));
                    }
                    else if (matchCondition.FilterMode == FilterMode.Attributes)
                    {
                        return(string.Format(CultureInfo.InvariantCulture, "\"{0}\" {1} \"{2}\""
                                             , matchCondition.ColumnName
                                             , matches
                                             , matchCondition.MatchExpression));
                    }
                    else
                    {
                        return(string.Format(CultureInfo.InvariantCulture, "\"{0}\" {1} \"{2}\""
                                             , "Caculated Area"
                                             , matches
                                             , matchCondition.MatchExpression));
                    }
                }
            }
            else
            {
                return(Binding.DoNothing);
            }
        }