예제 #1
0
        /// <summary>
        /// Comparison for two Brakes.
        /// </summary>
        /// <param name="break1">First <c>Brake</c>.</param>
        /// <param name="break2">Second <c>Brake</c>.</param>
        /// <returns>-1 if first break less then second, 0 if they are equal
        /// and 1 if first break more then second. </returns>
        public static int Compare(Break break1, Break break2)
        {
            // If first break == null.
            if (break1 == null)
            {
                if (break2 == null)
                {
                    return(0);
                }
                else
                {
                    return(-1);
                }
            }
            else if (break2 == null)
            {
                return(1);
            }

            // If both not null.
            if (break1.GetType() != break2.GetType())
            {
                return(0); // Breaks are not of the same type, cant compare.
            }
            else if (break1.GetType() == typeof(TimeWindowBreak))
            {
                TimeWindowBreak br1 = break1 as TimeWindowBreak;
                TimeWindowBreak br2 = break2 as TimeWindowBreak;

                return(_TimeWindowBreakComparer(br1, br2));
            }
            else if (break1.GetType() == typeof(WorkTimeBreak))
            {
                WorkTimeBreak br1 = break1 as WorkTimeBreak;
                WorkTimeBreak br2 = break2 as WorkTimeBreak;

                return(_WorkTimeBreakComparer(br1, br2));
            }
            else if (break1.GetType() == typeof(DriveTimeBreak))
            {
                DriveTimeBreak br1 = break1 as DriveTimeBreak;
                DriveTimeBreak br2 = break2 as DriveTimeBreak;

                return(_DriveTimeBreakComparer(br1, br2));
            }
            else
            {
                // Breaks are of unknown type, cant compare them.
                Debug.Assert(false);
                return(0);
            }
        }
        /// <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();
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Selecting template from dictionary.
        /// </summary>
        /// <param name="item">Break which is editing.</param>
        /// <param name="container">Ignored.</param>
        /// <returns>DataTemplate.</returns>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            Break br = (Break)item;

            return(DataTemplates[br.GetType()]);
        }
예제 #4
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();
                }
            }
        }