示例#1
0
        private void ButtonOkPlayer_Click(object sender, RoutedEventArgs e)
        {
            String titleBefore = TextBoxTitleBefore.Text.Trim();
            String firstName   = TextBoxFirstName.Text.Trim();
            String lastName    = TextBoxLastName.Text.Trim();

            int krpId       = 0;
            int yearOfBirth = 0;

            bool krpIdEx       = false;
            bool yearOfBirthEx = false;

            try { krpId = (TextBoxKrp.Text.Trim() != "") ? Int32.Parse(TextBoxKrp.Text) : 0; } catch (Exception ex) { krpIdEx = true; }
            try { yearOfBirth = (TextBoxYearOfBirth.Text.Trim() != "") ? Int32.Parse(TextBoxYearOfBirth.Text) : 0; } catch (Exception ex) { yearOfBirthEx = true; }

            var ageCategory = ComboBoxAgeCategories.SelectedItem;
            var club        = ComboBoxClubs.SelectedItem;

            int?clubId = _dbContext.GetClubIdByName((string)club);

            // V pripade ze bol zadany nespravny tvar pre ciselne hodnoty vyskoci warning
            if (krpIdEx || yearOfBirthEx)
            {
                MessageBox.Show("KRP or YearOfBirth has incorrect value!");
            }
            // Ked je vsetko OK, idem pridat hraca do DB
            else
            {
                Player player = new Player();
                player.KrpId       = krpId;
                player.TitleBefore = titleBefore;
                player.FirstName   = firstName;
                player.LastName    = lastName;
                player.YearOfBirth = yearOfBirth;
                player.AgeCategory = (AgeCategory?)ageCategory;
                player.ClubId      = clubId;

                // Overenie ci sa KRP v systeme nenachadza
                if (_dbContext.GetPlayerByKrp(krpId).Count > 0)
                {
                    MessageBoxResult result = MessageBox.Show($@"The player is already exists, do you wish continue?",
                                                              "Edit player", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel);
                    if (result == MessageBoxResult.OK)
                    {
                        // Aktualizovanie existujuceho hraca
                        _dbContext.UpdatePlayer(player);
                    }
                }
                else
                {
                    // Vlozenie noveho hraca
                    _dbContext.InsertPlayer(player);
                }
                _mainWindow.RefreshListPlayers();
                Close();
            }
        }
示例#2
0
        private static void ImportPlayers(FileHelperEngine <PlayersHeader> engine, String csvPath)
        {
            var records = engine.ReadFile(csvPath);

            // pouzijem pre pracu so stylom textu
            TextInfo textInfo = new CultureInfo("sk-SK", false).TextInfo;

            // rozparsujem data okrem 1. riadku (hlavicka)
            foreach (var record in records.Skip(1))
            {
                string priezvisko = record.Priezvisko.ToLower();
                priezvisko = textInfo.ToTitleCase(priezvisko); // potom capitalize

                string meno = record.Meno.ToLower();
                meno = textInfo.ToTitleCase(meno);

                int?materskyKlub = dbContext.GetClubIdByName(record.MaterskyKlub);

                AgeCategory vekovaKategoria;
                if (record.VekovaKategoria.ToLower().Contains("kadet"))
                {
                    vekovaKategoria = AgeCategory.Cadet;
                }
                else if (record.VekovaKategoria.ToLower().Contains("dorast"))
                {
                    vekovaKategoria = AgeCategory.Midgest;
                }
                else if (record.VekovaKategoria.ToLower().Contains("junior"))
                {
                    vekovaKategoria = AgeCategory.Junior;
                }
                else
                {
                    vekovaKategoria = AgeCategory.Senior;
                }

                try
                {
                    var player = new Player
                    {
                        LastName    = priezvisko,
                        FirstName   = meno,
                        TitleBefore = record.TitulPred,
                        YearOfBirth = int.Parse(record.RokNarodenia),
                        KrpId       = int.Parse(record.Krp),
                        ClubId      = materskyKlub,
                        AgeCategory = vekovaKategoria
                    };

                    if (dbContext.GetPlayerByKrp(player.KrpId).Count > 0)
                    {
                        Console.WriteLine($@"Hrac s KRP {player.KrpId} uz v systeme existuje, preto nebude vlozeny.");
                    }
                    else
                    {
                        dbContext.InsertPlayer(player);
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            }
        }