Beispiel #1
0
        private void OnWindowLoaded(object sender, RoutedEventArgs e)
        {
            if (IsNew)
            {
                _tripWaypoint = new TripWaypoint
                {
                    RowID        = Entities.TripWaypointViewModel.NextRecordNumber,
                    Trip         = Trip,
                    WaypointType = "Set",
                    SetNumber    = Entities.TripWaypointViewModel.NextSetNumber(Trip),
                };
                labelTitle.Content = "Add a waypoint";
                Title = "Add trip waypoint";
            }
            else
            {
                var wptForEditing = Entities.TripWaypointViewModel.GetTripWaypoint(TripWaypointID);
                _tripWaypoint = new TripWaypoint
                {
                    RowID               = wptForEditing.RowID,
                    SetNumber           = wptForEditing.SetNumber,
                    Trip                = wptForEditing.Trip,
                    WaypointName        = wptForEditing.WaypointName,
                    WaypointType        = wptForEditing.WaypointType,
                    TimeStamp           = wptForEditing.TimeStamp,
                    Waypoint            = wptForEditing.Waypoint,
                    WaypointGPXFileName = wptForEditing.WaypointGPXFileName
                };
                _oldWaypoint       = wptForEditing.Waypoint;
                _oldWaypoint.Name  = _tripWaypoint.WaypointName;
                labelTitle.Content = "Edit a trip waypoint";
                Title = "Edit trip waypoint";
            }

            PropertyGrid.AutoGenerateProperties = false;
            PropertyGrid.SelectedObject         = _tripWaypoint;

            PropertyGrid.PropertyDefinitions.Add(new PropertyDefinition {
                Name = "WaypointName", DisplayName = "Waypoint name", DisplayOrder = 1, Description = "Name of waypoint"
            });
            PropertyGrid.PropertyDefinitions.Add(new PropertyDefinition {
                Name = "WaypointType", DisplayName = "Waypoint type", DisplayOrder = 2, Description = "Select if waypoint is for setting or hauling of gear"
            });
            PropertyGrid.PropertyDefinitions.Add(new PropertyDefinition {
                Name = "TimeStampAdjusted", DisplayName = "Timestamp", DisplayOrder = 3, Description = "Timestamp of waypoint"
            });
            PropertyGrid.PropertyDefinitions.Add(new PropertyDefinition {
                Name = "SetNumber", DisplayName = "Set #", DisplayOrder = 4, Description = "Set number"
            });
            PropertyGrid.PropertyDefinitions.Add(new PropertyDefinition {
                Name = "Trip", DisplayName = "Trip ID", DisplayOrder = 5, Description = "Trip identifier"
            });
            PropertyGrid.PropertyDefinitions.Add(new PropertyDefinition {
                Name = "WaypointGPXFileName", DisplayName = "Source of waypoint", DisplayOrder = 6, Description = "GPX source"
            });
            PropertyGrid.PropertyDefinitions.Add(new PropertyDefinition {
                Name = "RowID", DisplayName = "ID", DisplayOrder = 7, Description = "Identifier"
            });
        }
Beispiel #2
0
        private void OnButtonClick(object sender, RoutedEventArgs e)
        {
            switch (((Button)sender).Name)
            {
            case "buttonOK":
                TripWaypoint tw = new TripWaypoint
                {
                    Trip                = _tripWaypoint.Trip,
                    WaypointName        = _tripWaypoint.WaypointName,
                    WaypointType        = _tripWaypoint.WaypointType,
                    TimeStamp           = _tripWaypoint.TimeStamp,
                    RowID               = _tripWaypoint.RowID,
                    SetNumber           = _tripWaypoint.SetNumber,
                    Waypoint            = _tripWaypoint.Waypoint,
                    WaypointGPXFileName = _tripWaypoint.WaypointGPXFileName
                };

                var result = Entities.TripWaypointViewModel.ValidateTrip(tw, IsNew, _oldWaypoint);
                if (result.ErrorMessage.Length == 0)
                {
                    bool saveSuccess;
                    if (IsNew)
                    {
                        saveSuccess = Entities.TripWaypointViewModel.AddRecordToRepo(tw);
                    }
                    else
                    {
                        saveSuccess = Entities.TripWaypointViewModel.UpdateRecordInRepo(tw);
                    }

                    DialogResult = saveSuccess;
                }
                else
                {
                    MessageBox.Show(result.ErrorMessage, "Validation error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                break;

            case "buttonCancel":
                DialogResult = false;
                break;
            }
        }