예제 #1
0
        /// <summary>
        /// Fill stops maptips list
        /// </summary>
        private void _CreateStopsTipsConfig(List <object> mapProperties, IList <object> selectedMapProperties, StringCollection selectedConfig)
        {
            Type type = typeof(Stop);

            PropertyInfo[] properties = type.GetProperties();
            foreach (PropertyInfo property in properties)
            {
                if (Attribute.IsDefined(property, typeof(DomainPropertyAttribute)))
                {
                    DomainPropertyAttribute attribute = (DomainPropertyAttribute)Attribute.GetCustomAttribute(property, typeof(DomainPropertyAttribute));
                    System.Diagnostics.Debug.Assert(null != attribute);
                    Type typeProperty = _GetEffectiveType(property.PropertyType);

                    Unit?displayUnits = null;
                    Unit?valueUnits   = null;
                    if (Attribute.IsDefined(property, typeof(UnitPropertyAttribute)))
                    {
                        UnitPropertyAttribute unitAttribute = (UnitPropertyAttribute)Attribute.GetCustomAttribute(
                            property, typeof(UnitPropertyAttribute));

                        displayUnits = (RegionInfo.CurrentRegion.IsMetric) ? unitAttribute.DisplayUnitMetric : unitAttribute.DisplayUnitUS;
                        valueUnits   = unitAttribute.ValueUnits;
                    }

                    if (!property.Name.Equals(Stop.PropertyNameMapLocation) && !property.Name.Equals(Stop.PropertyNameSequenceNumber))
                    {
                        _AddPropertyTip("", property.Name, attribute.Title, mapProperties,
                                        selectedMapProperties, selectedConfig, valueUnits, displayUnits);
                    }
                }
            }
        }
예제 #2
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        protected override void DoValidate(double objectToValidate, object currentTarget, string key, ValidationResults validationResults)
        {
            Type         type     = currentTarget.GetType();
            PropertyInfo property = type.GetProperty(key);

            UnitPropertyAttribute unitAttribute = (UnitPropertyAttribute)Attribute.GetCustomAttribute(property, typeof(UnitPropertyAttribute));

            Unit displayUnits = (RegionInfo.CurrentRegion.IsMetric)? unitAttribute.DisplayUnitMetric : unitAttribute.DisplayUnitUS;
            Unit valueUnits   = unitAttribute.ValueUnits;

            if ((objectToValidate < _minValue) || (_maxValue < objectToValidate))
            {
                string format = this.MessageTemplate;

                double maxValue = _maxValue;
                if (valueUnits != displayUnits)
                {
                    maxValue = UnitConvertor.Convert(maxValue, valueUnits, displayUnits);
                }

                string valueToDisplay = UnitFormatter.Format(maxValue, displayUnits);

                string message = string.Format(format, valueToDisplay);
                this.LogValidationResult(validationResults, message, currentTarget, key);
            }
        }
        /// <summary>
        /// Control loaded.
        /// </summary>
        void UnitTextBoxEditor_Loaded(object sender, RoutedEventArgs e)
        {
            Xceed.Wpf.DataGrid.CellContentPresenter cellContentPresenter = this.VisualParent as Xceed.Wpf.DataGrid.CellContentPresenter;
            Xceed.Wpf.DataGrid.DataCell             dataCell             = cellContentPresenter.TemplatedParent as Xceed.Wpf.DataGrid.DataCell;
            string columnName = dataCell.ParentColumn.FieldName;

            ESRI.ArcLogistics.Data.DataObject dataObject = dataCell.ParentRow.DataContext as ESRI.ArcLogistics.Data.DataObject;

            if (dataObject != null)
            {
                Type type = dataObject.GetType();

                PropertyInfo property = type.GetProperty(columnName);
                if (property != null)
                {
                    Attribute attr = Attribute.GetCustomAttribute(property, typeof(UnitPropertyAttribute));

                    UnitPropertyAttribute unitAttribute = (UnitPropertyAttribute)attr;

                    _typeConverter = TypeDescriptor.GetConverter(property.PropertyType);

                    _displayUnits = (RegionInfo.CurrentRegion.IsMetric) ? unitAttribute.DisplayUnitMetric : unitAttribute.DisplayUnitUS;
                    _valueUnits   = unitAttribute.ValueUnits;
                }

                _inited = true;

                _SetTextToInnerTextBox();
            }
            else
            {
                // If this is not DataObject
                Break breakObject = dataCell.ParentRow.DataContext as Break;
                if (breakObject != null)
                {
                    // If this is Break. Get it`s type and initiate control in a proper way.
                    Type         type     = breakObject.GetType();
                    PropertyInfo property = type.GetProperty(columnName);
                    if (property != null)
                    {
                        Attribute attr = Attribute.GetCustomAttribute(property, typeof(UnitPropertyAttribute));

                        UnitPropertyAttribute unitAttribute = (UnitPropertyAttribute)attr;

                        _typeConverter = TypeDescriptor.GetConverter(property.PropertyType);

                        _displayUnits = (RegionInfo.CurrentRegion.IsMetric) ? unitAttribute.DisplayUnitMetric : unitAttribute.DisplayUnitUS;
                        _valueUnits   = unitAttribute.ValueUnits;
                    }

                    _inited = true;

                    _SetTextToInnerTextBox();
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Add core properties of class
        /// </summary>
        private void _AddCoreProperty(PropertyInfo property, string prePath, DomainPropertyAttribute attribute,
                                      IList <object> mapProperties, IList <object> selectedMapProperties, StringCollection selectedConfig)
        {
            Unit?displayUnits = null;
            Unit?valueUnits   = null;

            if (Attribute.IsDefined(property, typeof(UnitPropertyAttribute)))
            {
                UnitPropertyAttribute unitAttribute = (UnitPropertyAttribute)Attribute.GetCustomAttribute(
                    property, typeof(UnitPropertyAttribute));

                displayUnits = (RegionInfo.CurrentRegion.IsMetric) ? unitAttribute.DisplayUnitMetric : unitAttribute.DisplayUnitUS;
                valueUnits   = unitAttribute.ValueUnits;
            }

            _AddPropertyTip(prePath, property.Name, attribute.Title, mapProperties,
                            selectedMapProperties, selectedConfig, valueUnits, displayUnits);
        }
예제 #5
0
        /// <summary>
        /// Initialize control.
        /// </summary>
        private void _Init()
        {
            Xceed.Wpf.DataGrid.CellContentPresenter cellContentPresenter = this.VisualParent as Xceed.Wpf.DataGrid.CellContentPresenter;
            if (cellContentPresenter == null)
            {
                return;
            }

            Xceed.Wpf.DataGrid.DataCell dataCell = cellContentPresenter.TemplatedParent as Xceed.Wpf.DataGrid.DataCell;
            string columnName = dataCell.ParentColumn.FieldName;

            ESRI.ArcLogistics.Data.DataObject dataObject = dataCell.ParentRow.DataContext as ESRI.ArcLogistics.Data.DataObject;

            if (dataObject != null)
            {
                int capacityPropertyIndex = Capacities.GetCapacityPropertyIndex(columnName);
                if (capacityPropertyIndex != -1)
                {
                    CapacityInfo capacityInfo = App.Current.Project.CapacitiesInfo[capacityPropertyIndex];
                    if (RegionInfo.CurrentRegion.IsMetric)
                    {
                        _displayUnits = capacityInfo.DisplayUnitMetric;
                    }
                    else
                    {
                        _displayUnits = capacityInfo.DisplayUnitUS;
                    }

                    _valueUnits = _displayUnits;
                }
                else
                {
                    Type         type     = dataObject.GetType();
                    PropertyInfo property = type.GetProperty(columnName);

                    UnitPropertyAttribute unitAttribute = (UnitPropertyAttribute)Attribute.GetCustomAttribute(property, typeof(UnitPropertyAttribute));

                    _displayUnits = (RegionInfo.CurrentRegion.IsMetric) ? unitAttribute.DisplayUnitMetric : unitAttribute.DisplayUnitUS;
                    _valueUnits   = unitAttribute.ValueUnits;
                }

                _TextBox.Text = UnitFormatter.Format(0.0, _displayUnits);

                _inited = true;

                _SetTextToInnerTextBox();
            }
            else
            {
                // If this is not DataObject
                Break breakObject = dataCell.ParentRow.DataContext as Break;
                if (breakObject != null)
                {
                    // If this is Break. Get it`s type and initiate control in a proper way.
                    Type type = breakObject.GetType();

                    PropertyInfo property = type.GetProperty(columnName);
                    if (property != null)
                    {
                        Attribute attr = Attribute.GetCustomAttribute(property, typeof(UnitPropertyAttribute));

                        UnitPropertyAttribute unitAttribute = (UnitPropertyAttribute)attr;

                        _displayUnits = (RegionInfo.CurrentRegion.IsMetric) ? unitAttribute.DisplayUnitMetric : unitAttribute.DisplayUnitUS;
                        _valueUnits   = unitAttribute.ValueUnits;
                    }

                    _TextBox.Text = UnitFormatter.Format(0.0, _displayUnits);

                    _inited = true;

                    _SetTextToInnerTextBox();
                }
            }
        }