Example #1
0
        private void PlayerBindingSource_AddingNew(object sender, AddingNewEventArgs e)
        {
            Player player = new Player {
                ID = DataCreation.UniqueRandomInt(this.players)
            };

            if (!RBNvisitor.Checked)
            {
                player.TagNumber = DataCreation.NextTagNumber(this.players);
            }
            e.NewObject = player;
            this.players.Add(player);
        }
        public override void HandleRow(string[] data)
        {
            // Identify:
            Player player = null;

            for (int i = 0; i < data.Length; i++)
            {
                switch (GetColumn(i).First())
                {
                case "Tag Number":
                    if (player == null && !string.IsNullOrEmpty(data[i]))
                    {
                        player = players.FirstOrDefault(p => p.TagNumber.Equals(data[i]));
                    }
                    break;

                case "Name":
                    player = players.FirstOrDefault(p => p.Name.Equals(data[i]));
                    break;
                }
            }
            if (player == null)
            {
                player = new Player {
                    ID = DataCreation.UniqueRandomInt(players)
                };
                players.Add(player);
            }
            // Import
            for (int i = 0; i < data.Length; i++)
            {
                switch (GetColumn(i).First())
                {
                case "Tag Number":
                    if (string.IsNullOrEmpty(data[i]))
                    {
                        break;
                    }
                    player.TagNumber = data[i];
                    break;

                case "Name":
                    if (string.IsNullOrEmpty(data[i]))
                    {
                        break;
                    }
                    player.Name = data[i];
                    break;

                case "Primary Position":
                    player.PositionPrimary = EnumStringConverter.ParsePosition(data[i]);
                    break;

                case "Primary Grade":
                    player.GradePrimary = EnumStringConverter.ParseGrade(data[i]);
                    break;

                case "Secondary Position":
                    player.PositionSecondary = EnumStringConverter.ParsePosition(data[i]);
                    break;

                case "Secondary Grade":
                    player.GradeSecondary = EnumStringConverter.ParseGrade(data[i]);
                    break;

                case "Primary Position and Grade":
                    player.PreferencePrimary = EnumStringConverter.ParsePositionAndGrade(data[i]);
                    break;

                case "Secondary Position and Grade":
                    player.PreferenceSecondary = EnumStringConverter.ParsePositionAndGrade(data[i]);
                    break;

                case "Team Size":
                    player.PreferredTeamSizes = EnumStringConverter.TryParseTeamSize(data[i], out TeamSize ts) ? ts : TeamSize.Any;
                    break;
                }
            }
            // Validate
            if (player.PositionPrimary == Position.None)
            {
                player.PositionPrimary = Position.Lead;
            }
            if (player.GradePrimary == Grade.None)
            {
                player.GradePrimary = Grade.G2;
            }
            if (player.PositionSecondary != Position.None && player.GradeSecondary == Grade.None)
            {
                player.GradeSecondary = player.GradePrimary;
            }
        }