private void UpdateValue(bool?addValue, object choiceValue)
        {
            var changedValue = choiceValue as GPString;

            if (changedValue == null)
            {
                return;
            }

            if (_multiValue == null)
            {
                _multiValue = new List <GPString>();
            }

            bool adding = (addValue.HasValue && addValue.Value);
            // check if the string in in the Value collection
            GPString obj    = null;
            bool     exists = false;

            foreach (GPString item in _multiValue)
            {
                if (item.Value.Equals(changedValue.Value))
                {
                    obj    = item;
                    exists = true;
                    break;
                }
            }
            if (adding)
            {
                if (!exists)
                {
                    _multiValue.Add(changedValue);
                }
            }
            else
            {
                if (exists)
                {
                    _multiValue.Remove(obj);
                }
            }

            val = new GPMultiValue <GPString>(val.Name, _multiValue);
        }
Example #2
0
        public static string ParameterToString(GPParameterType type, GPParameter param, CultureInfo culture)
        {
            if (param == null)
            {
                return(string.Empty);
            }
            switch (type)
            {
            case GPParameterType.Boolean:
                GPBoolean boo = param as GPBoolean;
                if (boo != null)
                {
                    return(boo.Value.ToString());
                }
                else
                {
                    return(string.Empty);
                }

            case GPParameterType.Date:
                GPDate date = param as GPDate;
                if (date != null && date.Value != null)
                {
                    return(date.Value.Ticks.ToString());
                }
                else
                {
                    return(string.Empty);
                }

            case GPParameterType.Double:
                GPDouble dub = param as GPDouble;
                if (dub != null && !double.IsNaN(dub.Value))
                {
                    return(dub.Value.ToString(culture));
                }
                else
                {
                    return(string.Empty);
                }

            case GPParameterType.Long:
                GPLong lon = param as GPLong;
                if (lon != null)
                {
                    return(lon.Value.ToString());
                }
                else
                {
                    return(string.Empty);
                }

            case GPParameterType.String:
                GPString stir = param as GPString;
                if (stir != null && stir.Value != null)
                {
                    return(stir.Value);
                }
                else
                {
                    return(string.Empty);
                }

            case GPParameterType.FeatureLayer:
                GPFeatureRecordSetLayer feat = param as GPFeatureRecordSetLayer;
                if (feat != null && feat.Url != null)
                {
                    return(feat.Url);
                }
                else
                {
                    return(string.Empty);
                }

            case GPParameterType.RecordSet:
                GPRecordSet rsl = param as GPRecordSet;
                if (rsl != null && rsl.Url != null)
                {
                    return(rsl.Url);
                }
                else
                {
                    return(string.Empty);
                }

            case GPParameterType.DataFile:
                GPDataFile dat = param as GPDataFile;
                if (dat != null && dat.Url != null)
                {
                    return(dat.Url);
                }
                else
                {
                    return(string.Empty);
                }
            }
            return(string.Empty);
        }
 public override void AddUI(Grid grid)
 {
     if (Config != null && Config.ShownAtRunTime)
     {
         if (Config.Type == GPParameterType.String && Config.ChoiceList != null &&
             Config.ChoiceList.Count > 1)
         {
             #region Create combo box
             ComboBox cb = new ComboBox()
             {
                 HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
                 Width      = 125,
                 Height     = 24,
                 Margin     = new Thickness(2),
                 Foreground = new SolidColorBrush(Colors.Black)
             };
             #region Populate items
             foreach (Choice choice in Config.ChoiceList)
             {
                 TextBlock item = new TextBlock()
                 {
                     Text                = choice.DisplayText,
                     Width               = 210,
                     TextTrimming        = System.Windows.TextTrimming.WordEllipsis,
                     HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
                     Tag = choice.Value
                 };
                 ToolTipService.SetToolTip(item, choice.DisplayText);
                 GPString value       = Value as GPString;
                 GPString choiceValue = choice.Value as GPString;
                 cb.Items.Add(item);
                 if (value != null && choiceValue != null && value.Value == choiceValue.Value)
                 {
                     cb.SelectedIndex = cb.Items.Count - 1;
                     cb.SelectedItem  = item;
                 }
             }
             #endregion
             cb.SelectionChanged += (a, b) =>
             {
                 Value = (GPParameter)((cb.SelectedItem as TextBlock).Tag);
                 RaiseCanExecuteChanged();
             };
             cb.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
             cb.SetValue(Grid.ColumnProperty, 1);
             cb.SetValue(ToolTipService.ToolTipProperty, Config.ToolTip);
             grid.Children.Add(cb);
             #endregion
         }
         else
         {
             #region
             string  text = ParameterToString(Config.Type, Value, CultureHelper.GetCurrentCulture());
             TextBox tb   = new TextBox()
             {
                 Text   = text == null ? string.Empty : text,
                 Margin = new Thickness(2),
                 HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch
             };
             tb.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
             tb.SetValue(Grid.ColumnProperty, 1);
             tb.SetValue(ToolTipService.ToolTipProperty, Config.ToolTip);
             grid.Children.Add(tb);
             tb.TextChanged += (s, e) =>
             {
                 Value = StringToParameter(Config.Name, Config.Type, tb.Text, CultureHelper.GetCurrentCulture());
                 RaiseCanExecuteChanged();
             };
             #endregion
         }
         RaiseCanExecuteChanged();
     }
 }