void IDropTarget.DragOver(IDropInfo dropInfo)
        {
            ParticipantCategory source = dropInfo.Data as ParticipantCategory;
            ParticipantCategory target = dropInfo.TargetItem as ParticipantCategory;

            if (source != null && target != null)
            {
                dropInfo.Effects           = DragDropEffects.Move;
                dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
            }
        }
Пример #2
0
        public bool Merge(ParticipantCategory c)
        {
            if (!ContainsSimilar(c))
            {
                Items.Add(c);
                Items.Sort(new StdComparer());
                return(true);
            }

            return(false);
        }
Пример #3
0
        public void Participant_IsEqualTo()
        {
            var sex1   = new ParticipantCategory('M');
            var sex2   = new ParticipantCategory('W');
            var class1 = new ParticipantClass("c1", null, "Class 1", sex1, 2000, 0);
            var class2 = new ParticipantClass("c2", null, "Class 1", sex2, 2000, 0);

            Participant p1 = new Participant
            {
                Name      = "Name",
                Firstname = "Firstname",
                Sex       = sex1,
                Year      = 2000,
                Club      = "Club",
                SvId      = "SvId",
                Code      = "Code",
                Nation    = "Nation",
                Class     = class1
            };

            Participant p2 = new Participant
            {
                Name      = "Name",
                Firstname = "Firstname",
                Sex       = sex1,
                Year      = 2000,
                Club      = "Club",
                SvId      = "SvId",
                Code      = "Code",
                Nation    = "Nation",
                Class     = class1
            };

            void performCheck()
            {
                Assert.IsFalse(p1.IsEqualTo(p2));
                p2.Assign(p1);
                Assert.IsTrue(p1.IsEqualTo(p2));
            }

            Assert.IsTrue(p1.IsEqualTo(p2));

            p2.Name      = "name"; performCheck();
            p2.Firstname = "fname"; performCheck();
            p2.Sex       = sex2; performCheck();
            p2.Year      = 1900; performCheck();
            p2.Club      = "c"; performCheck();
            p2.SvId      = "xyz"; performCheck();
            p2.Code      = "xyz"; performCheck();
            p2.Nation    = "xyz"; performCheck();
            p2.Class     = class2; performCheck();
            p2.Class     = null; performCheck();
        }
Пример #4
0
        public RaceParticipant createRaceParticipant(ParticipantClass cla = null, ParticipantCategory cat = null, double points = -1.0)
        {
            Participant     p  = createParticipant(cla: cla, cat: cat);
            RaceParticipant rp = _race.AddParticipant(p);

            if (points > 0)
            {
                rp.Points = points;
            }
            rp.StartNumber = uint.Parse(p.Id);

            return(rp);
        }
Пример #5
0
        private void storeCategories()
        {
            // *** Delete removed one
            List <ParticipantCategory> toDelete = new List <ParticipantCategory>();

            foreach (var cat2 in _dm.GetParticipantCategories())
            {
                ParticipantCategory cat1 = null;
                _category2Category.TryGetValue(cat2, out cat1);
                if (cat1 == null || CategoryViewModel.Items.FirstOrDefault(i => i == cat1) == null)
                {
                    toDelete.Add(cat2);
                }
            }
            foreach (var cat in toDelete)
            {
                _dm.GetParticipantCategories().Remove(cat);
                _category2Category.Remove(cat);
            }

            // *** Update & create new ones
            uint curSortPos = 1;

            foreach (var cat1 in CategoryViewModel.Items)
            {
                var found = _category2Category.FirstOrDefault(i => i.Value == cat1);  // Find original
                var cat2  = found.Key;
                cat2 = _dm.GetParticipantCategories().FirstOrDefault(i => i == cat2); // Check if already in DataModel

                if (cat2 != null)
                { // Update existing one
                    cat2.Name       = cat1.Name;
                    cat2.PrettyName = cat1.PrettyName;
                    cat2.Synonyms   = cat1.Synonyms;
                    cat2.SortPos    = curSortPos;
                }
                else
                { // Create new one
                    var catNew = new ParticipantCategory(cat1.Name, cat1.PrettyName, curSortPos, cat1.Synonyms);
                    _dm.GetParticipantCategories().Add(catNew);
                    // Remove any old reference and replace with new one
                    if (found.Key != null)
                    {
                        _category2Category.Remove(found.Key);
                    }
                    _category2Category.Add(catNew, cat1);
                }

                curSortPos++;
            }
        }
        void IDropTarget.Drop(IDropInfo dropInfo)
        {
            ParticipantCategory source = dropInfo.Data as ParticipantCategory;
            ParticipantCategory target = dropInfo.TargetItem as ParticipantCategory;

            if (source != null && target != null)
            {
                var iSource = _viewModel.Items.IndexOf(source);
                var iTarget = _viewModel.Items.IndexOf(target);

                if (iSource != iTarget)
                {
                    _viewModel.Items.Move(iSource, iTarget);
                }
            }
        }
Пример #7
0
        public void Category()
        {
            ParticipantCategory c1 = new ParticipantCategory();

            Assert.AreEqual(char.MinValue, c1.Name);
            Assert.IsNull(c1.Synonyms);
            Assert.AreEqual("", c1.PrettyName);
            Assert.AreEqual(uint.MaxValue, c1.SortPos);

            ParticipantCategory c2 = new ParticipantCategory('W');

            Assert.AreEqual('W', c2.Name);
            Assert.IsNull(c2.Synonyms);
            Assert.AreEqual("W", c2.PrettyName);
            Assert.AreEqual(uint.MaxValue, c2.SortPos);

            ParticipantCategory c3 = new ParticipantCategory('W', "Weiblich", 1);

            Assert.AreEqual('W', c3.Name);
            Assert.IsNull(c3.Synonyms);
            Assert.AreEqual("Weiblich", c3.PrettyName);
            Assert.AreEqual(1U, c3.SortPos);

            ParticipantCategory c4 = new ParticipantCategory('M', "Männlich", 2);

            Assert.AreEqual('M', c4.Name);
            Assert.IsNull(c4.Synonyms);
            Assert.AreEqual("Männlich", c4.PrettyName);
            Assert.AreEqual(2U, c4.SortPos);

            ParticipantCategory c5 = new ParticipantCategory('M', "Männlich", 2, "mHh");

            Assert.AreEqual('M', c5.Name);
            Assert.AreEqual("mHh", c5.Synonyms);
            Assert.AreEqual("Männlich", c5.PrettyName);
            Assert.AreEqual(2U, c5.SortPos);


            Assert.IsTrue(c1 != c2);
            Assert.IsTrue(c3 == c2);
            Assert.IsTrue(c3 != c4);
            Assert.IsTrue(c3.GetHashCode() == c2.GetHashCode());

            Assert.IsTrue(c3.CompareTo(c4) == -1);
            Assert.IsTrue(c4.CompareTo(c3) == 1);
            Assert.IsTrue(c3.CompareTo(c3) == 0);
        }
Пример #8
0
        public Participant createParticipant(ParticipantClass cla = null, ParticipantCategory cat = null)
        {
            _participantSerial++;

            var p = new Participant
            {
                Name      = string.Format("Name {0}", _participantSerial),
                Firstname = string.Format("Firstname {0}", _participantSerial),
                Sex       = cat,
                Id        = _participantSerial.ToString(),
                Class     = cla
            };

            Model.GetParticipants().Add(p);

            return(p);
        }
Пример #9
0
        private bool categoriesDifferent()
        {
            // *** Check removed one
            foreach (var cat2 in _dm.GetParticipantCategories())
            {
                ParticipantCategory cat1 = null;
                _category2Category.TryGetValue(cat2, out cat1);
                if (cat1 == null || CategoryViewModel.Items.FirstOrDefault(i => i == cat1) == null)
                {
                    return(true);
                }
            }

            // *** Check updated & new ones
            uint curSortPos = 1;

            foreach (var cat1 in CategoryViewModel.Items)
            {
                var found = _category2Category.FirstOrDefault(i => i.Value == cat1);  // Find original
                var cat2  = found.Key;
                cat2 = _dm.GetParticipantCategories().FirstOrDefault(i => i == cat2); // Check if already in DataModel

                if (cat2 != null)
                { // Check updated
                    if (cat2.Name != cat1.Name || cat2.PrettyName != cat1.PrettyName || cat2.Synonyms != cat1.Synonyms || cat2.SortPos != curSortPos)
                    {
                        return(true);
                    }
                }
                else
                {
                    return(true);
                }

                curSortPos++;
            }

            return(false);
        }
Пример #10
0
        ParticipantCategory importSex(string sex)
        {
            // Looks in category name first, afterwards in synonyms

            if (string.IsNullOrEmpty(sex))
            {
                return(null);
            }

            char sexInvariant = char.ToLowerInvariant(sex[0]);

            ParticipantCategory category = null;

            foreach (var c in _categories)
            {
                if (char.ToLowerInvariant(c.Name) == sexInvariant)
                {
                    category = c;
                    break;
                }
            }

            if (category == null)
            {
                foreach (var c in _categories)
                {
                    if (!string.IsNullOrEmpty(c.Synonyms) && c.Synonyms.ToLowerInvariant().Contains(sexInvariant))
                    {
                        category = c;
                        break;
                    }
                }
            }

            return(category);
        }
Пример #11
0
        public List <RaceParticipant> createRaceParticipants(int n, ParticipantClass cla = null, ParticipantCategory cat = null)
        {
            List <RaceParticipant> participants = new List <RaceParticipant>();

            for (int i = 0; i < n; i++)
            {
                participants.Add(createRaceParticipant(cla: cla, cat: cat));
            }

            return(participants);
        }
Пример #12
0
 public void RemoveCategory(ParticipantCategory c)
 {
 }
Пример #13
0
 public void CreateOrUpdateCategory(ParticipantCategory c)
 {
 }
Пример #14
0
 public bool ContainsSimilar(ParticipantCategory c)
 {
     return(Items.Contains(c));
 }
Пример #15
0
        public void Import(AppDataModel srcModel)
        {
            var srcGroups     = srcModel.GetParticipantGroups();
            var srcClasses    = srcModel.GetParticipantClasses();
            var srcCategories = srcModel.GetParticipantCategories();


            // TODO: only really added items are allowed to be in _x2x maps otherwise, class becomes inconsistent or points to a wrong group/category

            foreach (var g1 in srcGroups)
            {
                if (!GroupViewModel.ContainsSimilar(g1))
                {
                    ParticipantGroup g2 = null;
                    if (!_group2Group.TryGetValue(g1, out g2))
                    {
                        g2 = new ParticipantGroup(g1.Id, g1.Name, g1.SortPos);
                        _group2Group.Add(g1, g2);
                        GroupViewModel.Merge(g2);
                    }
                    else
                    {
                        System.Diagnostics.Debug.Assert(false);
                    }
                }
            }

            foreach (var cat1 in srcCategories)
            {
                if (!CategoryViewModel.ContainsSimilar(cat1))
                {
                    ParticipantCategory cat2 = null;
                    if (!_category2Category.TryGetValue(cat1, out cat2))
                    {
                        cat2 = new ParticipantCategory(cat1.Name, cat1.PrettyName, cat1.SortPos, cat1.Synonyms);
                        _category2Category.Add(cat1, cat2);
                        CategoryViewModel.Merge(cat2);
                    }
                    else
                    {
                        System.Diagnostics.Debug.Assert(false);
                    }
                }
            }

            foreach (var c1 in srcClasses)
            {
                if (!ClassViewModel.ContainsSimilar(c1))
                {
                    ParticipantClass c2 = null;
                    if (!_class2Class.TryGetValue(c1, out c2))
                    {
                        c2 = new ParticipantClass(
                            c1.Id,
                            c1.Group == null ? null : _group2Group[c1.Group],
                            c1.Name,
                            c1.Sex == null ? null : _category2Category[c1.Sex],
                            c1.Year,
                            c1.SortPos);
                        _class2Class.Add(c1, c2);
                        ClassViewModel.Merge(c2);
                    }
                    else
                    {
                        System.Diagnostics.Debug.Assert(false);
                    }
                }
            }
        }