예제 #1
0
        private void ImportRating(XmlExporter.RatingNode ratingNode)
        {
            pbOperationProgress.Value   = 0;
            pbOperationProgress.Maximum = ratingNode.Ratings.Count;
            lblTotalProgress.Text       = Localizator.Dictionary.GetString("IMPORT_RATINGS");// "Импортирование рейтингов";
            lblOperationProgress.Text   = ratingNode.Game.Name;
            Application.DoEvents();
            ImportTypeOfSport(ratingNode.Game);
            foreach (PlayerRating rating in ratingNode.Ratings)
            {
                if (Globals.Players.ContainsKey(rating.Guid))
                {
                    rating.Id = Globals.Players[rating.Guid].Id;
#if FEDITION
                    DatabaseManager.CurrentDb.PlayerBeginRatingUpdate(new PlayerRatingInfo(ratingNode.Game.Id, rating.Id, rating.RatingBegin, true));
#endif
#if STANDARD
                    DatabaseManager.CurrentDb.PlayerBeginRatingUpdate(new PlayerRatingInfo(ratingNode.Game.Id, rating.Id, rating.Rating, true));
#endif
                }
                else
                {
                    AddErrorText(Localizator.Dictionary.GetString("NOT_FOUND"), rating.Name.ToString());
                }
                pbOperationProgress.Value += 1;
                Application.DoEvents();
            }
        }
예제 #2
0
        private bool ParseImport(string filename)
        {
            IImporter importer = Importer.GetImporter(filename);

            if (importer != null && importer.Open(filename))
            {
                mainTreeView.Nodes.Clear();
                PlayerInfo[] players = importer.GetPlayers();
                if (players != null && players.Length > 0)
                {
                    TreeNode node = new TreeNode(Localizator.Dictionary.GetString("PLAYER_LIST"));
                    node.Tag = players;
                    mainTreeView.Nodes.Add(node);
                }
                TypeOfSport[] games = importer.GetTypesOfSport();
                if (games != null && games.Length > 0)
                {
                    TreeNode node = new TreeNode(Localizator.Dictionary.GetString("RATING_LISTS"));
                    node.Tag = games;
                    mainTreeView.Nodes.Add(node);
                    foreach (TypeOfSport sport in games)
                    {
                        TreeNode child = new TreeNode();
                        child.Text = sport.Name;
                        XmlExporter.RatingNode rating_node = new XmlExporter.RatingNode();
                        rating_node.Game = sport;
                        rating_node.Ratings.AddRange(importer.GetPlayersRatings(sport));
                        child.Tag = rating_node;
                        node.Nodes.Add(child);
                    }
                }

                Tournament[] tourns = importer.GetTournaments();
                if (tourns != null && tourns.Length > 0)
                {
                    TreeNode node = new TreeNode();
                    node.Text = Localizator.Dictionary.GetString("TOURNAMENTS");// "Турниры";
                    node.Tag  = tourns;
                    mainTreeView.Nodes.Add(node);
                    CompetitionList comps = new CompetitionList();
                    foreach (Tournament tour in tourns)
                    {
                        TreeNode child = new TreeNode();
                        child.Text = String.Format("{0} - {1}", tour.Info.DateBegin.ToString("dd.MM.yyyy"), tour.Info.Name);
                        child.Tag  = tour;
                        node.Nodes.Add(child);
                        foreach (Competition comp in tour.Competitions.Values)
                        {
                            TreeNode sub_child = new TreeNode();
                            sub_child.Text = comp.Info.Name;
                            sub_child.Tag  = comp;
                            child.Nodes.Add(sub_child);
                        }
                    }
                    mainTreeView.ExpandAll();
                }
                return(true);
            }
            return(false);
        }
        private void ImportRatings()
        {
            FRatings.Clear();
            TypeOfSportList games = new TypeOfSportList();

            database.ReadTypeOfSportList(games);
            foreach (TypeOfSport game in games.Values)
            {
                XmlExporter.RatingNode node = new XmlExporter.RatingNode();
                node.Game = game;
                TA.RatingSystem.PlayersRatingList ratings = new TA.RatingSystem.PlayersRatingList();
                database.ReadPlayerRatingList(game.Id, ratings);
                node.Ratings.AddRange(ratings.Values);
                FRatings.Add(game, node);
            }
        }
예제 #4
0
        public virtual bool Open(string pathToXml)
        {
            try
            {
                XmlTextReader reader = new XmlTextReader(pathToXml);
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:        // Узел является элементом.
                        if (reader.Name == "CM_XML")
                        {
                            FDate    = DateTime.ParseExact(reader.GetAttribute("date"), "yyyyMMdd", CultureInfo.InvariantCulture);
                            FAppGuid = new Guid(reader.GetAttribute("app_guid"));
                        }
                        if (reader.Name == "MEMBERS")
                        {
                            FPlayers.Clear();
                        }
                        if (reader.Name == "MEMBER")
                        {
                            PlayerInfo player = new PlayerInfo();
                            player.Identifier     = new Guid(reader.GetAttribute("GUID"));
                            player.NickName       = reader.GetAttribute("nick");
                            player.LastName       = reader.GetAttribute("lname");
                            player.FirstName      = reader.GetAttribute("fname");
                            player.PatronymicName = reader.GetAttribute("pname");
                            player.Country        = reader.GetAttribute("country");
                            player.City           = reader.GetAttribute("city");
                            player.Phone          = reader.GetAttribute("phones");
                            player.EMail          = reader.GetAttribute("email");

                            // в trial версии можно экспортировать за раз не более 10 игроков
                            if (EditionManager.Edition != EditionType.Mini)
                            {
                                if (!EditionManager.IsTrial || FPlayers.Count < 10)     // в trial версии можно экспортировать за раз не более 10 игроков
                                {
                                    FPlayers.Add(player);
                                }
                            }
                        }
                        if (reader.Name == "RATINGS")
                        {
                            // Начинаем экспортирование рейтингов
                            FRatings.Clear();
                        }
                        if (reader.Name == "RATING")
                        {
                            rating_node           = new XmlExporter.RatingNode();
                            rating_node.Game      = new TypeOfSport();
                            rating_node.Game.Id   = Convert.ToInt32(reader.GetAttribute("id"));
                            rating_node.Game.Name = reader.GetAttribute("name");
                            // в trial версии можно экспортировать за раз не более 1 рейтинга
                            if (EditionManager.Edition != EditionType.Mini)
                            {
                                if (!EditionManager.IsTrial || FRatings.Count < 1)
                                {
                                    FRatings.Add(rating_node.Game, rating_node);
                                }
                            }
                        }
                        if (reader.Name == "PLAYER_RATING")
                        {
                            if (EditionManager.Edition != EditionType.Mini)
                            {
                                if (rating_node == null)
                                {
                                    throw new Exception("Не задан рейтинговый лист");
                                }
                                PlayerRating rating = new PlayerRating();
                                string       date   = reader.GetAttribute("date");
                                if (date != "")
                                {
                                    rating.LastRatingDate = DateTime.ParseExact(date, "yyyyMMdd", CultureInfo.InvariantCulture);
                                }
                                rating.Guid        = new Guid(reader.GetAttribute("guid"));
                                rating.RatingBegin = Convert.ToInt32(reader.GetAttribute("start"));
                                rating.Rating      = Convert.ToInt32(reader.GetAttribute("current"));
                                rating.Name        = reader.GetAttribute("name");
                                rating_node.Ratings.Add(rating);
                            }
                        }
                        if (reader.Name == "TOURNAMENTS")
                        {
                            FTournaments.Clear();
                        }
                        if (reader.Name == "TOURNAMENT")
                        {
                            tournament = new Tournament();
                            tournament.Info.DateBegin = DateTime.ParseExact(reader.GetAttribute("begin"), "yyyyMMdd", CultureInfo.InvariantCulture);
                            tournament.Info.DateEnd   = DateTime.ParseExact(reader.GetAttribute("end"), "yyyyMMdd", CultureInfo.InvariantCulture);
                            tournament.Info.Name      = reader.GetAttribute("name");
                            tournament.Info.Place     = reader.GetAttribute("place");

                            if (EditionManager.Edition != EditionType.Mini && EditionManager.Edition != EditionType.Standard)
                            {
                                if (!EditionManager.IsTrial || FTournaments.Count < 1)     // в trial версии можно экспортировать за раз не более 1 турнира
                                {
                                    FTournaments.Add(tournament);
                                }
                            }
                        }
                        if (reader.Name == "COMPETITIONS")
                        {
                            if (tournament == null)
                            {
                                throw new Exception("Tournamet is not initialized");
                            }
                            tournament.Competitions.Clear();
                        }
                        if (reader.Name == "COMPETITION")
                        {
                            TA.Corel.CompetitionInfo ci = new TA.Corel.CompetitionInfo();
                            ci.ChangesRating        = Convert.ToBoolean(reader.GetAttribute("rating"));
                            ci.CompetitionType.Id   = Convert.ToInt32(reader.GetAttribute("type"));
                            ci.CompetitionType.Name = reader.GetAttribute("type_name");
                            ci.Date         = DateTime.ParseExact(reader.GetAttribute("date"), "yyyyMMdd", CultureInfo.InvariantCulture);
                            ci.Name         = reader.GetAttribute("name");
                            ci.SportType.Id = Convert.ToInt32(reader.GetAttribute("sport"));
                            ci.Status       = (TA.Corel.CompetitionInfo.CompetitionState)(Enum.Parse(typeof(TA.Corel.CompetitionInfo.CompetitionState), reader.GetAttribute("status")));
                            competition     = TA.Competitions.CompetitionFactory.CreateCompetition(ci);
                            // в trial версии можно экспортировать за раз не более 1 соревнования
                            if (!EditionManager.IsTrial || tournament.Competitions.Count < 1)
                            {
                                tournament.Competitions.Add(tournament.Competitions.Count + 1, competition);
                            }
                        }
                        if (reader.Name == "PARAMS")
                        {
                            if (competition == null)
                            {
                                throw new Exception("Competition is not initialized");
                            }
                            competition.Info.Properties.Clear();
                        }
                        if (reader.Name == "PARAM")
                        {
                            if (competition == null)
                            {
                                throw new Exception("Competition is not initialized");
                            }
                            competition.Info.Properties.Add(reader.GetAttribute("name"), reader.GetAttribute("value"));
                        }
                        if (reader.Name == "PLAYERS")
                        {
                            if (competition == null)
                            {
                                throw new Exception("Competition is not initialized");
                            }
                            competition.Players.Clear();
                        }
                        if (reader.Name == "PLAYER")
                        {
                            if (competition == null)
                            {
                                throw new Exception("Competition is not initialized");
                            }
                            CompetitionPlayerInfo pi = new CompetitionPlayerInfo();
                            pi.Identifier = new Guid(reader.GetAttribute("guid"));
                            pi.Place      = new TA.Utils.StringAlt(reader.GetAttribute("place"));
                            pi.RatingBeforeCompetition = Convert.ToInt32(reader.GetAttribute("rating"));
                            pi.SeedNo      = Convert.ToInt32(reader.GetAttribute("seed"));
                            pi.StartPoints = Convert.ToInt32(reader.GetAttribute("start_points"));
                            pi.RebuyPoints = Convert.ToInt32(reader.GetAttribute("rebuy_points"));
                            competition.Players.Add(competition.Players.Count + 1, pi);
                        }

                        if (reader.Name == "MATCHES")
                        {
                            if (competition == null)
                            {
                                throw new Exception("Competition is not initialized");
                            }
                            competition.Matches.Clear();
                        }
                        if (reader.Name == "MATCH")
                        {
                            if (competition == null)
                            {
                                throw new Exception("Competition is not initialized");
                            }
                            match             = new MatchInfo();
                            match.Label.Label = reader.GetAttribute("label");
                            match.Loosers_MatchLabel.Label = reader.GetAttribute("looser_label");
                            match.Winners_MatchLabel.Label = reader.GetAttribute("winner_label");
                            match.Winner = (MatchLabel.PlayerLetters)Enum.Parse(typeof(MatchLabel.PlayerLetters), reader.GetAttribute("winner"));
                            competition.Matches.Add(competition.Matches.Count + 1, match);
                        }
                        if (reader.Name == "PLAYER_A")
                        {
                            if (match == null)
                            {
                                throw new Exception("Match is not initialized");
                            }
                            match.PlayerA.Id     = Convert.ToInt32(reader.GetAttribute("id"));
                            match.PlayerA.Guid   = new Guid(reader.GetAttribute("guid"));
                            match.PlayerA.Points = Convert.ToInt32(reader.GetAttribute("points"));
                            match.PlayerA.Tag    = Convert.ToInt32(reader.GetAttribute("tag"));
                        }
                        if (reader.Name == "PLAYER_B")
                        {
                            if (match == null)
                            {
                                throw new Exception("Match is not initialized");
                            }
                            match.PlayerB.Id     = Convert.ToInt32(reader.GetAttribute("id"));
                            match.PlayerB.Guid   = new Guid(reader.GetAttribute("guid"));
                            match.PlayerB.Points = Convert.ToInt32(reader.GetAttribute("points"));
                            match.PlayerB.Tag    = Convert.ToInt32(reader.GetAttribute("tag"));
                        }
                        break;
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }