Example #1
0
        private void BindSelectedStop(bool bRefreshUpdatableAttributes)
        {
            if (_defaultButtonBackgroud == null)
            {
                _defaultButtonBackgroud = AtStopButton.Background;
            }

            if (StopsListBox.SelectedItems.Count == 0)
            {
                return;
            }

            //Stop stop = e.AddedItems[0] as Stop;
            Stop stop = StopsListBox.SelectedItems[0] as Stop;

            if (stop == null)
            {
                return;
            }

            // Stop ID
            string stopId = stop.GetPropertyValueAsString(Stop.IdFieldAlias);

            if (stopId == null)
            {
                Log.Trace("Stop Details - missing stop ID field alias - '" + Stop.IdFieldAlias + "'");
                stopId = "";
            }
            StopNameText.Text = stopId;

            // Stop Address
            string address = stop.GetPropertyValueAsString(Stop.AddressFieldAlias);

            if (address == null)
            {
                Log.Trace("Stop Details - missing address field alias - '" + Stop.AddressFieldAlias + "'");
                address = "";
            }
            StopAddressText.Text = address;

            // Stop Sequence
            string sequence = stop.GetPropertyValueAsString(Stop.SequenceFieldAlias);

            if (sequence == null)
            {
                Log.Trace("Stop Details - missing sequence field alias - '" + Stop.SequenceFieldAlias + "'");
                sequence = "";
            }
            StopSequenceText.Text = "#" + sequence;

            // Stop Type
            string type = stop.Type;

            if (type == null)
            {
                type = "Stop";
            }

            StopTypeText.Text = type;

            // Stop Image
            StopImage.Source = stop.ImageSource;

            // Stop ETA
            StopEtaText.Text = stop.ETA;

            // Stop ETD
            StopEtdText.Text = stop.ETD;

            // Stop Status
            string status = stop.Status;

            if (status == null)
            {
                status = "";
            }

            // AtStop Button
            string key = type + "," + Stop.StopStatusAtStop;

            string[] buttonRemarks = GetStatusRemarks(key);
            if (buttonRemarks == null || buttonRemarks.Length == 0)
            {
                AtStopButton.Visibility = Visibility.Collapsed;
            }
            else
            {
                AtStopButton.Visibility = Visibility.Visible;
            }

            if (status.Equals(Stop.StopStatusAtStop))
            {
                AtStopButton.Background = _highlightedButtonBackgroud;
            }
            else
            {
                AtStopButton.Background = _defaultButtonBackgroud;
            }

            // Completed Button
            key           = type + "," + Stop.StopStatusCompleted;
            buttonRemarks = GetStatusRemarks(key);
            if (buttonRemarks == null || buttonRemarks.Length == 0)
            {
                CompletedButton.Visibility = Visibility.Collapsed;
            }
            else
            {
                CompletedButton.Visibility = Visibility.Visible;
            }

            if (status.Equals(Stop.StopStatusCompleted))
            {
                CompletedButton.Background = _highlightedButtonBackgroud;
            }
            else
            {
                CompletedButton.Background = _defaultButtonBackgroud;
            }

            // Exception Button
            key           = type + "," + Stop.StopStatusException;
            buttonRemarks = GetStatusRemarks(key);
            if (buttonRemarks == null || buttonRemarks.Length == 0)
            {
                ExceptionButton.Visibility = Visibility.Collapsed;
            }
            else
            {
                ExceptionButton.Visibility = Visibility.Visible;
            }

            if (status.Equals(Stop.StopStatusException))
            {
                ExceptionButton.Background = _highlightedButtonBackgroud;
            }
            else
            {
                ExceptionButton.Background = _defaultButtonBackgroud;
            }

            // Attributes
            stopAttributesDataGrid.ItemsSource = stop.GetAttributes();

            // Updatable Attributes
            if (bRefreshUpdatableAttributes)
            {
                stopUpdatableAttributesDataGrid.ItemsSource = stop.UpdatableAttributes;
            }

            // Show or hide the Updates Stack Panel
            if (stopUpdatableAttributesDataGrid.ItemsSource == null || ((ObservableCollection <ItemAttribute>)stopUpdatableAttributesDataGrid.ItemsSource).Count == 0)
            {
                UpdatesStackPanel.Visibility = Visibility.Collapsed;
            }
            else
            {
                UpdatesStackPanel.Visibility = Visibility.Visible;
            }
        }