//static readonly ILog _log = LogManager.GetLogger(typeof(HullRaceFilterConverter));
        //if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); }
        //if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); }

        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            HullRace   selectedRace = null;
            int        vesselSide   = -1;
            Visibility retVal       = Visibility.Visible;

            if (values != null)
            {
                if (values.Length > 0)
                {
                    selectedRace = values[0] as HullRace;
                }
                if (values.Length > 1)
                {
                    if (!int.TryParse(values[1].ToString(), out vesselSide))
                    {
                        vesselSide = -1;
                    }
                }
                if (selectedRace == null || selectedRace.ID < 0 || vesselSide == selectedRace.ID)
                {
                    retVal = Visibility.Visible;
                }
                else
                {
                    retVal = Visibility.Collapsed;
                }
            }
            return(retVal);
        }
        private void AddRace_click(object sender, RoutedEventArgs e)
        {
            HullRace race = new HullRace();

            race.ID = Data.HullRaces.Count;
            Data.HullRaces.Add(race);
        }
        private void DeleteRace_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;

            if (b != null)
            {
                HullRace race = b.CommandParameter as HullRace;
                if (race != null)
                {
                    if (Locations.MessageBoxShow(AMLResources.Properties.Resources.AreYouSure, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        HullRaceCollection r = new HullRaceCollection();
                        foreach (HullRace oldr in Data.HullRaces)
                        {
                            if (oldr != race)
                            {
                                r.Add(oldr);
                            }
                        }
                        Data.HullRaces = r;
                        ValidateVesselData();
                    }
                }
            }
        }
        void LoadHullRaceFilter()
        {
            if (Data != null)
            {
                HullRaceFilter = new HullRaceCollection();
                HullRace allRaces = new HullRace();
                allRaces.ID   = -1;
                allRaces.Name = "Any race";
                HullRaceFilter.Add(allRaces);
                if (Data.HullRaces != null)
                {
                    foreach (HullRace race in Data.HullRaces)
                    {
                        HullRaceFilter.Add(race);
                    }

                    if (!HullRaceEventSubscribed)
                    {
                        Data.HullRaces.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(HullRaces_CollectionChanged);
                        HullRaceEventSubscribed           = true;
                    }
                }
            }
        }
Esempio n. 5
0
        private void Done_Click(object sender, RoutedEventArgs e)
        {
            bool isInvalid = false;
            List <DictionaryEntry> raceConflictsToRemove = new List <DictionaryEntry>();

            foreach (DictionaryEntry entry in RaceConflicts)
            {
                HullRace race = (HullRace)entry.Key;

                if (race.Tag == null)
                {
                    isInvalid = true;
                }
                else
                {
                    if (race.Tag.ToString() == "Source")
                    {
                        race = (HullRace)entry.Value;
                    }
                    RaceResolved.Add(race);
                    raceConflictsToRemove.Add(entry);
                }
            }
            List <DictionaryEntry> vesselConflictsToRemove = new List <DictionaryEntry>();

            foreach (DictionaryEntry entry in VesselConflicts)
            {
                Vessel vessel = (Vessel)entry.Key;

                if (vessel.Tag == null)
                {
                    isInvalid = true;
                }
                else
                {
                    if (vessel.Tag.ToString() == "Source")
                    {
                        vessel = (Vessel)entry.Value;
                    }
                    VesselResolved.Add(vessel);
                    vesselConflictsToRemove.Add(entry);
                }
            }
            foreach (DictionaryEntry entry in raceConflictsToRemove)
            {
                RaceConflicts.Remove(entry);
            }
            foreach (DictionaryEntry entry in vesselConflictsToRemove)
            {
                VesselConflicts.Remove(entry);
            }
            if (isInvalid)
            {
                Locations.MessageBoxShow("Some conflicts remain unresolved.  Please resolve them.", MessageBoxButton.OK, MessageBoxImage.Stop);
            }
            else
            {
                DialogResult = true;
                this.Close();
            }
        }