/// <summary>
        /// React on commit item.
        /// </summary>
        public void CommitItem(DataGridItemCancelEventArgs e)
        {
            if (!e.Cancel)
            {
                _geocodablePage.OnCommittingEdit(e, true);

                Project project = App.Current.Project;
                if (project != null)
                {
                    project.Save();
                }

                DataGridControlEx dataGrid = _parentPage.OrdersView.OrdersGrid;
                if (dataGrid.SelectedItems == null)
                {
                    string status = string.Format((string)App.Current.FindResource(OptimizeAndEditPage.NoSelectionStatusFormat),
                                                  _currentSchedule.Routes.Count, _currentSchedule.UnassignedOrders.Count);
                    App.Current.MainWindow.StatusBar.SetStatus(_parentPage, status);
                    return;
                }

                _statusBuilder.FillSelectionStatus(e.CollectionView.Count,
                                                   (string)App.Current.FindResource("Order"), dataGrid.SelectedItems.Count, _parentPage);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="dataGrid">DataGridControlEx.</param>
        ///
        public ValidationCalloutController(DataGridControlEx dataGrid)
        {
            // Check input parameter.
            Debug.Assert(dataGrid != null);

            // Init fields.
            _dataGrid = dataGrid;
            var context = DataGridControl.GetDataGridContext(_dataGrid);

            _collection = context.Items;

            // When page loaded - do validation and subscribe to events.
            dataGrid.Loaded += (sender, args) =>
            {
                // Do initial validation.
                _Validate();

                // Subscribe to events.
                _InitEventHandlers();
            };

            // When page unloaded - close callout and unsubscribe from events.
            dataGrid.Unloaded += (sender, args) =>
            {
                // Close popup.
                _ClosePopup(false);

                // Unsubscribe from events.
                _UnsubscribeFromEvents();
            };

            // Init timer, which will hide callout.
            _InitTimer();
        }
        /// <summary>
        /// Remove items from collection.
        /// </summary>
        /// <param name="collection">Collection, from which items will removed.</param>
        /// <param name="removedItems">Items to remove.</param>
        private void _RemoveItems(IList collection, IList removedItems)
        {
            Debug.Assert(collection != null);
            Debug.Assert(removedItems != null);

            int collectionIndex = _collections.IndexOf(collection);
            DataGridControlEx datagridControl = _grids[collectionIndex];

            foreach (object remItem in removedItems)
            {
                if (datagridControl != null)
                {
                    // Check selected item is in main context.
                    if (collection.Contains(remItem))
                    {
                        collection.Remove(remItem);
                    }
                    else
                    {
                        // Remove from child context.
                        datagridControl.RemoveFromChildContextSelection(remItem);
                    }
                }
                else
                {
                    collection.Remove(remItem);
                }
            }
        }
        /// <summary>
        /// React on selection changed in grid.
        /// </summary>
        /// <param name="sender">Grid with changed selection.</param>
        /// <param name="e">Changed event args.</param>
        protected void _GridSelectionChanged(object sender, DataGridSelectionChangedEventArgs e)
        {
            Debug.Assert(sender != null);
            Debug.Assert(e != null);

            DataGridControlEx grid = (DataGridControlEx)sender;

            if (grid.SelectedItems == _suspendedCollection)
            {
                return; // skip events from suspended collection
            }
            var addedItems = e.SelectionInfos
                             .SelectMany(info => info.AddedItems)
                             .ToList();
            DataGridControlEx datagrid = (DataGridControlEx)e.Source;

            _FilterInvalidChanges(datagrid.SelectedItems, addedItems);

            var removedItems = e.SelectionInfos
                               .SelectMany(info => info.RemovedItems)
                               .ToList();
            var args = CommonHelpers.GetSelectionChangedArgs(addedItems, removedItems);

            if (args != null)
            {
                _CollectionChanged(grid.SelectedItems, args);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create RegionsPage.
        /// </summary>
        /// <param name="mapCtrl">Map from parent page.</param>
        /// <param name="dataGridControl">Grid from parent page.</param>
        /// <param name="parentLayer">Layer, that contains regions.</param>
        /// <param name="type">Semantic type of regions. Barrier or Zone.</param>
        /// <param name="layoutRoot">Parent page layout root.</param>
        /// <param name="mapBorder">Container element for map.</param>
        public RegionsPage(MapControl mapCtrl, DataGridControlEx dataGridControl, ObjectLayer parentLayer,
                           Type type, Grid layoutRoot, Border mapBorder)
        {
            _mapCtrl = mapCtrl;
            _mapCtrl.CanSelectCallback       = _CanSelect;
            _mapCtrl.StartEditRegionCallback = _EditStarted;
            _mapCtrl.EndEditRegionCallback   = _EditEnded;

            _dataGridControl = dataGridControl;

            _parentLayer = parentLayer;

            _type = type;

            if (_type == typeof(Zone))
            {
                _polygonTool             = new ZonePolygonTool();
                _polygonTool.OnComplete += new EventHandler(_PolygonToolOnComplete);
                _mapCtrl.AddTool(_polygonTool, _CanActivateZonePolygonTool);
            }
            else if (_type == typeof(Barrier))
            {
                _CreateBarrierTools();
            }
            else
            {
                Debug.Assert(false);
            }

            _gridAutoFitHelper = new GridAutoFitHelper(dataGridControl, layoutRoot, mapBorder);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Make this grid visible and hide all other.
        /// </summary>
        /// <param name="grid">DataGridControlEx.</param>
        private void _InitGridVisibility(DataGridControlEx grid)
        {
            DriveTimeGrid.Visibility  = System.Windows.Visibility.Collapsed;
            WorkTimeGrid.Visibility   = System.Windows.Visibility.Collapsed;
            TimeWindowGrid.Visibility = System.Windows.Visibility.Collapsed;

            grid.Visibility = System.Windows.Visibility.Visible;
        }
        /// <summary>
        /// Register grid collection.
        /// </summary>
        /// <param name="grid">Grid to register.</param>
        protected void _RegisterCollection(DataGridControlEx grid)
        {
            Debug.Assert(grid != null);
            Debug.Assert(_grids != null);

            grid.SelectionChanged += new DataGridSelectionChangedEventHandler(_GridSelectionChanged);
            _grids.Add(grid);
            _AddCollection(grid.SelectedItems);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Hide "PostalCode2" column.
        /// </summary>
        /// <param name="dataGridControl">Datagrid control to hide column.</param>
        public static void HidePostalCode2Column(DataGridControlEx dataGridControl)
        {
            string postalCode2ColumnName = AddressPart.PostalCode2.ToString();

            if (dataGridControl.Columns[postalCode2ColumnName] != null)
            {
                dataGridControl.Columns[postalCode2ColumnName].Visible = false;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="dataGridControl">Grid from parent page.</param>
        /// <param name="layoutRoot">Parent page layout root.</param>
        /// <param name="mapContainer">Container element for map.</param>
        public GridAutoFitHelper(DataGridControlEx dataGridControl, Grid layoutRoot, FrameworkElement mapContainer)
        {
            _dataGridControl = dataGridControl;
            _dataGridControl.OnItemSourceChanged += new EventHandler(_DataGridControlItemSourceChanged);

            _layoutRoot = layoutRoot;

            _mapContainer              = mapContainer;
            _mapContainer.SizeChanged += new SizeChangedEventHandler(_MapContainerSizeChanged);

            _ProcessNewItemsSource();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Do bring item into view.
        /// </summary>
        /// <param name="item">Item to bring into view.</param>
        private void _BringItemIntoView(object item)
        {
            Debug.Assert(item != null);

            DataGridControlEx dataGridControl = _GetParentDataGridControl(item);

            if (dataGridControl != null)
            {
                dataGridControl.BringItemIntoView(item);
            }

            _postponedBringItemIntoViewInvoked = false;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Init grid structure for Grid.
        /// </summary>
        /// <param name="gridStructure">Structure of the grid.</param>
        /// <param name="gridSettingsRepositoryName">Repository with grid settings.</param>
        /// <param name="grid">Grid.</param>
        /// <param name="collectionSource">Grid's collection source.</param>
        private void _InitGridStructure(string gridStructure, string gridSettingsRepositoryName,
                                        DataGridControlEx grid, DataGridCollectionViewSource collectionSource)
        {
            // Initializing gridstructure and gridlayout.
            GridStructureInitializer structureInitializer = new GridStructureInitializer
                                                                (gridStructure);

            structureInitializer.BuildGridStructure(collectionSource, grid);
            GridLayoutLoader layoutLoader = new GridLayoutLoader(gridSettingsRepositoryName,
                                                                 collectionSource.ItemProperties);

            layoutLoader.LoadLayout(grid);
        }
Exemplo n.º 12
0
        /// <summary>
        /// React on items source changing.
        /// </summary>
        /// <param name="sender">Sender view.</param>
        /// <param name="e">Ignored.</param>
        private void _GridItemsSourceChanging(object sender, EventArgs e)
        {
            DataGridControlEx dataGridControl = _GetDataGridControlByView(sender);

            if (_collectionBinding.IsCollectionRegistered(dataGridControl.SelectedItems))
            {
                _ListViewContextChangingHandler(sender);
            }
            else
            {
                _optimizeAndEditPage.Dispatcher.BeginInvoke(new RegisterDataGridDelegate(_ListViewContextChangingHandler),
                                                            DispatcherPriority.Input, sender);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Get grid from view.
        /// </summary>
        /// <param name="view">View.</param>
        /// <returns>Grid.</returns>
        private DataGridControlEx _GetDataGridControlByView(object view)
        {
            Debug.Assert(view != null);

            DataGridControlEx dataGridControl = null;

            if (view == _ordersView)
            {
                dataGridControl = _ordersView.OrdersGrid;
            }
            else if (view == _routesView)
            {
                dataGridControl = _routesView.RoutesGrid;
            }

            return(dataGridControl);
        }
Exemplo n.º 14
0
        /// <summary>
        /// React on changes in multicollection binding.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Multi collection changed event args.</param>
        private void _CollectionBindingNotifyMultiCollectionChanged(object sender, NotifyMultiCollectionChangedEventArgs e)
        {
            IList initiator = e.Initiator;

            DataGridControlEx initiatorGrid = null;

            if (initiator == _routesView.RoutesGrid.SelectedItems)
            {
                initiatorGrid = _routesView.RoutesGrid;
            }
            else if (initiator == _ordersView.OrdersGrid.SelectedItems)
            {
                initiatorGrid = _ordersView.OrdersGrid;
            }

            // Check that need to clear selection - if initiator is selected items of datagridcontrol and item was add.
            if ((e.EventArgs.Action == NotifyCollectionChangedAction.Add || e.EventArgs.Action == NotifyCollectionChangedAction.Replace) &&
                initiatorGrid != null && initiatorGrid.SelectedItemsFromAllContexts.Count > 0)
            {
                object firstSelectedItem = e.EventArgs.NewItems[0];

                // In case of shift or control adding element need to check type of new element.
                // if type of new element can't be selected with old selected.
                bool needToClearCollections = true;
                if (Keyboard.Modifiers == ModifierKeys.Control || Keyboard.Modifiers == ModifierKeys.Shift)
                {
                    needToClearCollections = !_CanSelect(firstSelectedItem);
                }

                if (needToClearCollections && !_postponedSelectionClearInvoked)
                {
                    _optimizeAndEditPage.Dispatcher.BeginInvoke(new DelegateWithItemParam(_PostponedClearingInvoked),
                                                                DispatcherPriority.Send, firstSelectedItem);

                    _postponedSelectionClearInvoked = true;
                }
            }

            _CallBringItemIntoViewIfNeeded(e);

            if (NotifyMultiCollectionChanged != null)
            {
                NotifyMultiCollectionChanged(sender, e);
            }
        }
        /// <summary>
        /// Remove items from collection.
        /// </summary>
        /// <param name="newItemsList">Items to remove.</param>
        /// <param name="collSender">Collection to remove items.</param>
        private void _RemoveFromCollection(IList newItemsList, IList collSender)
        {
            Debug.Assert(newItemsList != null);
            Debug.Assert(collSender != null);
            Debug.Assert(DataGridList != null);

            IsRecursive = true;

            // Find grid from which needs to remove items.
            int dataGridIndex            = Collections.IndexOf(collSender);
            DataGridControlEx parentGrid = DataGridList[dataGridIndex];

            Debug.Assert(parentGrid != null);

            // Go through items to remove collection and remove them from initiator collection.
            foreach (object item in newItemsList)
            {
                // If item in main collection - remove it.
                if (collSender.Contains(item))
                {
                    collSender.Remove(item);
                }
                else
                {
                    // Find child context, that contain this item.
                    DataGridContext parentDataGridContext       = null;
                    IEnumerable <DataGridContext> childContexts = parentGrid.GetChildContexts();
                    foreach (DataGridContext dataGridContext in childContexts)
                    {
                        if (dataGridContext.SelectedItems.Contains(item))
                        {
                            parentDataGridContext = dataGridContext;
                            break;
                        }
                    }

                    // Remove item from selection.
                    parentDataGridContext.SelectedItems.Remove(item);
                }
            }

            IsRecursive = false;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Get data grid which contains item.
        /// </summary>
        /// <param name="item">Item to find.</param>
        /// <returns>Data grid which contains item.</returns>
        private DataGridControlEx _GetParentDataGridControl(object item)
        {
            Debug.Assert(item != null);

            DataGridControlEx parentDataGridControl = null;

            if (item is Order)
            {
                parentDataGridControl = _ordersView.OrdersGrid;
            }
            else if ((item is Route) || (item is Stop))
            {
                parentDataGridControl = _routesView.RoutesGrid;
            }
            else
            {
                Debug.Assert(false); // not supported
            }

            return(parentDataGridControl);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Get margin for button panel which needs to lie opposite to current item in datagridcontrol.
        /// </summary>
        /// <param name="currentItem">Current item.</param>
        /// <param name="dataGridControl">Data grid control.</param>
        /// <param name="defaultRowHeight">Default data grid control row heigth.</param>
        /// <returns>Margin for button panel to set it opposite to current item in datagridcontrol.</returns>
        public static Thickness GetItemContainerMargin(object currentItem, DataGridControlEx dataGridControl, double defaultRowHeight)
        {
            var row = dataGridControl.GetContainerFromItem(currentItem)
                      as Xceed.Wpf.DataGrid.DataRow;

            var margin = new Thickness();

            if (null == row)
            {
                // Current item not yet set.
                margin.Top = dataGridControl.Margin.Top + defaultRowHeight + 1;
            }
            else
            {
                try
                {
                    // Get coords relatively to window.
                    var   leftTopPoint    = new Point(0, 0);
                    Point rowLeftTopPoint = row.PointFromScreen(leftTopPoint);

                    Point dataGridControlLeftTopPoint =
                        dataGridControl.PointFromScreen(leftTopPoint);

                    // Use diff of coords to set offset from top of DataGridControl and ButtonPanel parent grid.
                    margin.Top = dataGridControl.Margin.Top - rowLeftTopPoint.Y +
                                 dataGridControlLeftTopPoint.Y;
                }
                catch
                {
                    // Workaround: Sometimes visual is not connected.
                    margin.Top = dataGridControl.Margin.Top + defaultRowHeight + 1;
                }
            }

            return(margin);
        }
 /// <summary>
 /// Register grid collection.
 /// </summary>
 /// <param name="grid">Grid to register.</param>
 /// <param name="multiCollectionFilter">Collection filter.</param>
 public void RegisterCollection(DataGridControlEx grid, MultiCollectionFilter multiCollectionFilter)
 {
     _multiCollectionFilters.Add(multiCollectionFilter);
     _RegisterCollection(grid);
 }
Exemplo n.º 19
0
        /// <summary>
        /// Register grid collection.
        /// </summary>
        /// <param name="grid">Grid to register.</param>
        public void RegisterCollection(DataGridControlEx grid)
        {
            Debug.Assert(grid != null);

            _RegisterCollection(grid);
        }