Example #1
0
        /// <summary>
        /// Пересчитывает рейтинг и обновляет грид
        /// </summary>
        public void UpdateRatingAfterGrid()
        {
            //Пересичтывать рейтинг, только если это FedEdition
            if (!FCompetition.Info.ChangesRating)
            {
                lvRatingAfter.Visible = false;
                return;
            }

#if FEDITION
            string game_name = FCompetition.Info.SportType.Name;
            TA.RatingSystem.RatingSystem    RS = TA.RatingSystem.Builder.RatingSystemBuilder.CreateRatingSystem(FCompetition.Info.SportType.Id, game_name);
            TA.RatingSystem.CompetitionInfo competitionInfo = RS.Competitions.GetCompetitionById(FCompetition.Info.Id);

            lvRatingAfter.Clear();
            if (FCompetition.Info != null && competitionInfo != null)
            {
                DatabaseManager.CurrentDb.ReadCompetitionPlayersList(FCompetition, CompetitionPlayerList.SortByField.Name);
                foreach (CompetitionPlayerInfo player in FCompetition.PlayersResults)
                {
                    if (competitionInfo.Results.ContainsKey(player.Id))
                    {
                        TA.RatingSystem.PlayersCompetitionResult res = competitionInfo.Results[player.Id];
                        res.PlayerName = player.FullName;
                        lvRatingAfter.Add(res);
                    }
                }
            }
#endif
        }
        public static void SaveRatingSystemToXml(RatingSystem RatingSystem, string filename, DateTime date)
        {
            string xsl_filename = Path.GetFileNameWithoutExtension(filename) + ".xsl";

            File.Copy("RatingXSL.xslt", Path.Combine(Path.GetDirectoryName(filename), xsl_filename), true);
            PlayersRatingList current_rating = GetPlayersRating(RatingSystem.GameTypeId, date);
            XmlDocument       doc            = new XmlDocument();

            // Аттрибуты документа
            doc.AppendChild(doc.CreateXmlDeclaration("1.0", Encoding.UTF8.WebName, String.Empty));
            doc.AppendChild(doc.CreateProcessingInstruction("xml-stylesheet", String.Format("type='text/xsl' href='{0}'", xsl_filename)));

            // Создаем корневой узел
            XmlNode RootNode = doc.CreateElement("RatingSystem");

            RootNode.Attributes.Append(doc.CreateAttribute("Date")).Value     = date.ToString("dd.MM.yyyy");
            RootNode.Attributes.Append(doc.CreateAttribute("GameType")).Value = RatingSystem.GameTypeId.ToString();
            RootNode.Attributes.Append(doc.CreateAttribute("GameName")).Value = RatingSystem.GameTypeName;
            doc.AppendChild(RootNode);

            // Узел соревнований
            XmlNode CompetitionsNode = doc.CreateElement("Competitions");

            foreach (CompetitionInfo comp in RatingSystem.Competitions)
            {
                XmlNode competitionNode = doc.CreateElement("Competition");
                competitionNode.Attributes.Append(doc.CreateAttribute("Date")).Value = comp.Date.ToString("dd.MM.yyyy");
                CompetitionsNode.AppendChild(competitionNode);
            }
            RootNode.AppendChild(CompetitionsNode);

            // Узел результатов
            XmlNode ResultsNode = doc.CreateElement("Results");

            foreach (PlayerRating player in current_rating.Values)
            {
                XmlNode playerNode = doc.CreateElement("Player");
                playerNode.Attributes.Append(doc.CreateAttribute("Guid")).Value          = player.Guid.ToString();
                playerNode.Attributes.Append(doc.CreateAttribute("FName")).Value         = player.FName;
                playerNode.Attributes.Append(doc.CreateAttribute("PName")).Value         = player.PName;
                playerNode.Attributes.Append(doc.CreateAttribute("LName")).Value         = player.LName;
                playerNode.Attributes.Append(doc.CreateAttribute("Nick")).Value          = player.Name;
                playerNode.Attributes.Append(doc.CreateAttribute("EMail")).Value         = player.EMail;
                playerNode.Attributes.Append(doc.CreateAttribute("Phone")).Value         = player.Phone;
                playerNode.Attributes.Append(doc.CreateAttribute("Country")).Value       = player.Country;
                playerNode.Attributes.Append(doc.CreateAttribute("City")).Value          = player.City;
                playerNode.Attributes.Append(doc.CreateAttribute("RatingBegin")).Value   = player.RatingBegin.ToString();
                playerNode.Attributes.Append(doc.CreateAttribute("RatingCurrent")).Value = player.Rating.ToString();
                foreach (TA.RatingSystem.CompetitionInfo comp in RatingSystem.Competitions)
                {
                    XmlNode resultNode = doc.CreateElement("Result");
                    resultNode.Attributes.Append(doc.CreateAttribute("Date")).Value = comp.Date.ToString("dd.MM.yyyy");
                    string penalty = "";
                    string points  = "";
                    if (comp.Results.ContainsKey(player.Id))
                    {
                        TA.RatingSystem.PlayersCompetitionResult res = comp.Results[player.Id];
                        penalty = res.Penalty == 0 ? "" : (-res.Penalty).ToString();
                        points  = res.Delta.ToString();
                        if (res.Delta > 0)
                        {
                            points = "+" + points;
                        }
                    }
                    resultNode.Attributes.Append(doc.CreateAttribute("Penalty")).Value = penalty;
                    resultNode.Attributes.Append(doc.CreateAttribute("Points")).Value  = points;
                    playerNode.AppendChild(resultNode);
                }
                ResultsNode.AppendChild(playerNode);
            }
            RootNode.AppendChild(ResultsNode);
            doc.Save(filename);
        }