예제 #1
0
        private void PLSplash_Enter(object sender, EventArgs e)
        {
            string value = getSelectedPLLoadOptionOn();
            bool proceedToClose = false;

            if (string.Equals(PLConstants.LO_LOAD_SEASON, value)) {
                string path = "";
                OpenFileDialog loadSeasonDialog = new OpenFileDialog();
                loadSeasonDialog.Title = "Open Season File";
                loadSeasonDialog.Filter = "XML files|*.xml";
                loadSeasonDialog.InitialDirectory = @"C:\Program Files (x86)\PickLeague\Seasons";
                if (loadSeasonDialog.ShowDialog() == DialogResult.OK) {
                    path = loadSeasonDialog.FileName;
                    currSeason = PLXmlParser.parseXmlIntoSeason(path);
                    proceedToClose = true;
                }
            } else if (string.Equals(PLConstants.LO_NEW_SEASON, value)) {
                currSeason = new Season();
                proceedToClose = true;
            }

            if (proceedToClose) {
                this.Close();
            }
        }
예제 #2
0
        public static void parseWeek(Season currSeason, XmlNode weekNode)
        {
            Week newWeek = new Week();
            foreach (XmlNode subWeekNode in weekNode.ChildNodes) {
                if (nodeEquals(subWeekNode, PLConstants.WV_WEEK_ID)) {
                    newWeek.setWeekID(subWeekNode.InnerText);
                } else if (nodeEquals(subWeekNode, PLConstants.DO_MATCHUP)) {
                    parseMatchup(newWeek, subWeekNode);
                }
            }

            currSeason.getWeekDict().Add(newWeek.getWeekID(), newWeek);
        }
예제 #3
0
        public static void generateOutboundXml(Season currSeason, string path)
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.NewLineOnAttributes = true;
            // todo add dynamic file saving.
            XmlWriter writer = XmlWriter.Create(path, settings);

            writer.WriteStartElement(PLConstants.DO_SEASON);
            writer.WriteElementString(PLConstants.SV_SEASON_ID, currSeason.getSeasonID());

            /* ---------------- Player Info ---------------- */
            writer.WriteStartElement(PLConstants.DO_PLAYER_CONTAINER);
            // Writes out the information for each player.
            foreach (Player player in currSeason.getPlayerList()) {
                writer.WriteStartElement(PLConstants.DO_PLAYER);
                writer.WriteElementString(PLConstants.PV_FIRST, player.getFirstName());
                writer.WriteElementString(PLConstants.PV_LAST, player.getLastName());
                writer.WriteElementString(PLConstants.PV_PLAYER_ID, player.getPlayerID());
                writer.WriteElementString(PLConstants.PV_PLAYER_WINS, player.getWinsTotal().ToString());
                writer.WriteElementString(PLConstants.PV_PLAYER_LOSSES, player.getLossesTotal().ToString());
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            /* ---------------- Week Info ---------------- */
            writer.WriteStartElement(PLConstants.DO_WEEK_CONTAINER);
            // Grabs the keys and sorts them in ascending order.
            List<string> keyList = currSeason.getWeekDict().Keys.OrderBy(c => int.Parse(c)).ToList();
            foreach (string key in keyList) {
                Week currWeek = currSeason.getWeekDict()[key];
                writer.WriteStartElement(PLConstants.DO_WEEK);
                writer.WriteElementString(PLConstants.WV_WEEK_ID, currWeek.getWeekID());
                foreach (Matchup matchup in currWeek.getMatchupList()) {
                    writer.WriteStartElement(PLConstants.DO_MATCHUP);
                    writer.WriteElementString(PLConstants.MV_HOME_TEAM_ID, matchup.getHomeTeamID());
                    writer.WriteElementString(PLConstants.MV_AWAY_TEAM_ID, matchup.getAwayTeamID());
                    writer.WriteElementString(PLConstants.MV_MATCHUP_ID, matchup.getMatchupID());
                    writer.WriteElementString(PLConstants.MV_WINNER_ID, matchup.getWinnerID());
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }

            writer.Flush();
            writer.Close();
        }
예제 #4
0
        public static void parsePlayer(Season currSeason, XmlNode playerNode)
        {
            Player newPlayer = new Player();
            foreach (XmlNode infoNode in playerNode.ChildNodes) {
                if (nodeEquals(infoNode, PLConstants.PV_FIRST)) {
                    newPlayer.setFirstName(infoNode.InnerText);
                } else if (nodeEquals(infoNode, PLConstants.PV_LAST)) {
                    newPlayer.setLastName(infoNode.InnerText);
                } else if (nodeEquals(infoNode, PLConstants.PV_PLAYER_ID)) {
                    newPlayer.setPlayerID(infoNode.InnerText);
                } else if (nodeEquals(infoNode, PLConstants.PV_PLAYER_WINS)) {
                    newPlayer.setWinsTotal(Int32.Parse(infoNode.InnerText));
                } else if (nodeEquals(infoNode, PLConstants.PV_PLAYER_LOSSES)) {
                    newPlayer.setLossesTotal(Int32.Parse(infoNode.InnerText));
                }
            }

            currSeason.getPlayerList().Add(newPlayer);
        }
예제 #5
0
        public static Season parseXmlIntoSeason(string path)
        {
            Season currSeason = new Season();
            XmlDocument doc = new XmlDocument();

            doc.Load(path);
            foreach (XmlNode node in doc.DocumentElement.ChildNodes) {
                if (nodeEquals(node, PLConstants.SV_SEASON_ID)) {
                    currSeason.setSeasonID(node.InnerText);
                } else if (nodeEquals(node, PLConstants.DO_PLAYER_CONTAINER)) {
                    foreach (XmlNode playerNode in node.ChildNodes) {
                        parsePlayer(currSeason, playerNode);
                    }
                } else if (nodeEquals(node, PLConstants.DO_WEEK_CONTAINER)) {
                    foreach (XmlNode weekNode in node.ChildNodes) {
                        parseWeek(currSeason, weekNode);
                    }
                }
            }

            return currSeason;
        }
예제 #6
0
 public PLMainForm(Season season)
 {
     currSeason = season;
     InitializeComponent();
 }