示例#1
0
        protected bool ImportFromZgsExcel()
        {
            StatusChange("Import file is from Ziggys Google Docs Scoreboard Master Schedule Sheet");
            bool bret = false;
            ZgsXlsPlayerRec plrec = new ZgsXlsPlayerRec();
            string CurrentSeries = "";
            int iRowCount = 0;

            StatusChange("Obtain Rosters");
            ISheet sheet = Sheets["Sheet2"];
            StatusChange("Obtaining Player Names and Teams");
            for (int irow = 0; irow <= sheet.LastRowNum; irow++)
            {
                if ((irow > 0) && (irow % 100 == 0)) StatusChange("Processed " + irow.ToString() + " out of " + sheet.LastRowNum.ToString());

                IRow row = sheet.GetRow(irow);
                iRowCount++;
                if (row != null)
                {
                    if (irow == 0)
                    {
                        dictHeaders = HeadersToDict(row, out arrHeaderNames);
                        plrec = new ZgsXlsPlayerRec(dictHeaders, arrHeaderNames);
                    }
                    else
                    {
                        this.RecordCount++;
                        if (plrec.FromIRow(row))
                        {
                            if (!plrec.TeamName.Equals("Team"))
                            {
                                if (!this.PlayerList.ContainsKey(plrec.CodeName))
                                {
                                    this.PlayerList.Add(plrec.CodeName, null);
                                    if (!TeamKeyXRefList.ContainsKey(plrec.TeamNameKey)) TeamKeyXRefList.Add(plrec.TeamNameKey, plrec.TeamName);
                                    PlayerTeamList.Add(plrec.CodeName, plrec.TeamNameKey);
                                }
                            }
                        }
                    }
                }
            }

            ZgsXlsRec rec = new ZgsXlsRec();
            iRowCount = 0;
            sheet = Sheets.Values.First();
            decimal? LastGameNo = -1;
            string LastGameId = "";
            string LastSeries = "";
            DateTime? LastStartDateTime = DateTime.MaxValue;
            DateTime? StartDateTime = DateTime.MaxValue;
            StatusChange("Making a first pass to get Series, PackSets, Unique Team Names");
            for (int irow = 0; irow <= sheet.LastRowNum; irow++)
            {
                if ((irow > 0) && (irow % 100 == 0)) StatusChange("1st Pass: Processed " + irow.ToString() + " out of " + sheet.LastRowNum.ToString());

                IRow row = sheet.GetRow(irow);
                iRowCount++;
                if (row != null)
                {
                    if (irow == 0)
                    {
                        dictHeaders = HeadersToDict(row, out arrHeaderNames);
                        rec = new ZgsXlsRec(dictHeaders, arrHeaderNames);
                    }
                    else
                    {
                        this.RecordCount++;
                        if (rec.FromIRow(row))
                        {
                            // IF the first cell doesn't have anything in it, then it must be a series header
                            if ((rec.GameNo == null) || (row.FirstCellNum > 0 ))
                            {
                                //if (!this.SeriesList.ContainsKey(rec.GameId)) this.SeriesList.Add(rec.GameId, null);
                                //CurrentSeries = rec.GameId;
                            }
                            else
                            {
                                StartDateTime = rec.StartDateTime.Value;
                                //Each game is uniquely defined by StartDateTime (I know, shitty architecture, but it makes indexing easy without having to deal with concatented keys)
                                //  If a game is at the same time,  jsut add a second to differentate it.   very kludgy I know....
                                if (LastStartDateTime == rec.StartDateTime)
                                {
                                    StartDateTime = StartDateTime.Value.AddSeconds(1);
                                }

                                if (!this.SeriesList.ContainsKey(rec.Series)) this.SeriesList.Add(rec.Series, null);
                                CurrentSeries = rec.Series;
                                if (!this.TeamList.ContainsKey(rec.TeamA)) this.TeamList.Add(rec.TeamA, null);
                                if (!this.TeamList.ContainsKey(rec.TeamB)) this.TeamList.Add(rec.TeamB, null);
                                if ((rec.TeamC != null) && (rec.TeamC.Length > 0))
                                {
                                    if (!this.TeamList.ContainsKey(rec.TeamC)) this.TeamList.Add(rec.TeamC, null);
                                }

                                if (!this.MatchList.ContainsKey(StartDateTime))
                                {
                                    LsrXlsMatchData matchdata = new LsrXlsMatchData() { ScheduledDate = StartDateTime, ScoringMethodTypeName = "T", SeriesName = CurrentSeries };
                                    this.MatchList.Add(StartDateTime, matchdata);
                                }
                                if (!this.MatchList[StartDateTime].TeamData.ContainsKey(rec.TeamA))
                                {
                                    var teamData = new LsrXlsTeamData() { PackSet = rec.ColorA, TeamName = rec.TeamA };
                                    this.MatchList[StartDateTime].TeamData.Add(rec.TeamA, teamData);
                                }
                                if (!this.MatchList[StartDateTime].TeamData.ContainsKey(rec.TeamB))
                                {
                                    var teamData = new LsrXlsTeamData() { PackSet = rec.ColorB, TeamName = rec.TeamB };
                                    this.MatchList[StartDateTime].TeamData.Add(rec.TeamB, teamData);
                                }
                                if ((rec.TeamC != null) && (!this.MatchList[StartDateTime].TeamData.ContainsKey(rec.TeamC)))
                                {
                                    var teamData = new LsrXlsTeamData() { PackSet = rec.ColorC, TeamName = rec.TeamC };
                                    this.MatchList[StartDateTime].TeamData.Add(rec.TeamC, teamData);
                                }
                                if (!this.PackSetList.ContainsKey(rec.ColorA)) this.PackSetList.Add(rec.ColorA, null);
                                if (!this.PackSetList.ContainsKey(rec.ColorB)) this.PackSetList.Add(rec.ColorB, null);
                                if ((rec.ColorC != null) && (!this.PackSetList.ContainsKey(rec.ColorC))) this.PackSetList.Add(rec.ColorC, null);
                                LastGameNo = rec.GameNo;
                                LastGameId = rec.GameId;
                                LastSeries = rec.Series;
                                LastStartDateTime = rec.StartDateTime;
                            }
                            this.RowCount++;
                        }
                    }

                }
            }

            this.EventSync();
            this.SeriesSync(this.eventCurrent.id, this.SeriesList);
            this.TeamsSync(this.eventCurrent.id, this.TeamList);
            this.PlayersSync(this.eventCurrent.id, this.PlayerList);
            this.PackSetSync(this.eventCurrent.id, this.PackSetList);
            this.MatchSync(this.eventCurrent.id);

            int iMatchProcessed = 0;
            foreach (KeyValuePair<DateTime?, LsrXlsMatchData> kvpMatch in MatchList)
            {
                if ((iMatchProcessed > 0) && (iMatchProcessed % 50 == 0)) StatusChange("Adding Players to Matches: Processed " + iMatchProcessed.ToString() + " out of " + MatchList.Count.ToString());

                StartDateTime = kvpMatch.Key;
                LsrXlsMatchData matchData = MatchList[StartDateTime];
                foreach (KeyValuePair<string, LsrXlsTeamData> kvpTeam in matchData.TeamData)
                {
                    LsrXlsTeamData teamData = kvpTeam.Value;
                    var lstPlayersInTeam =
                        from p in PlayerTeamList
                        where p.Value.Equals(teamData.TeamName)
                        select p.Key;
                    foreach (string sCodeName in lstPlayersInTeam)
                    {
                        match matchObject = matchData.MatchObject;
                        player playerObject = PlayerList[sCodeName];
                        match_player matchPlayer = matchPlayerRepo.Get(matchObject.id, playerObject.id);
                        if (matchPlayer == null)
                        {
                            matchPlayer = new match_player() { match_id = matchObject.id, player_id = playerObject.id };
                            matchPlayer = matchPlayerRepo.Insert(matchPlayer);
                        }
                        else
                        {
                            //matchPlayer.score = 0;
                            matchPlayerRepo.Update(matchPlayer);
                        }

                    }
                }
                iMatchProcessed++;
            }
            return bret;
        }
示例#2
0
        protected bool ImportFromLsrExcel()
        {
            bool bret = false;
            LsrXlsRec rec = new LsrXlsRec();
            int iRowCount = 0;
            ISheet sheet = Sheets.Values.First();

            StatusChange("Making a first pass to get Series, PackSets, Unique Team Names, and unique Player Names");
            for (int irow = 0; irow <= sheet.LastRowNum; irow++)
            {
                if ((irow > 0) && (irow % 100 == 0)) StatusChange("1st Pass: Processed " + irow.ToString() + " out of " + sheet.LastRowNum.ToString());

                IRow row = sheet.GetRow(irow);
                iRowCount++;
                if (row != null)
                {
                    if (irow == 0)
                    {
                        dictHeaders = HeadersToDict(row, out arrHeaderNames);
                        rec = new LsrXlsRec(dictHeaders, arrHeaderNames);
                    }
                    else
                    {
                        this.RecordCount++;
                        if (rec.FromIRow(row))
                        {
                            if (!this.SeriesList.ContainsKey(rec.Series)) this.SeriesList.Add(rec.Series, null);
                            if (!this.TeamList.ContainsKey(rec.TeamName)) this.TeamList.Add(rec.TeamName, null);
                            if (!this.PlayerList.ContainsKey(rec.PlayerName))
                            {
                                this.PlayerList.Add(rec.PlayerName, null);
                                PlayerTeamList.Add(rec.PlayerName, rec.TeamName);
                            }
                            if (!this.MatchList.ContainsKey(rec.GameTime))
                            {
                                LsrXlsMatchData matchdata = new LsrXlsMatchData() { ScheduledDate = rec.GameTime, ScoringMethodTypeName = rec.ScoringType, SeriesName = rec.Series };
                                this.MatchList.Add(rec.GameTime, matchdata);
                            }
                            if (!this.MatchList[rec.GameTime].TeamData.ContainsKey(rec.TeamName))
                            {
                                var teamData = new LsrXlsTeamData() { PackSet = rec.PackSet, TeamName = rec.TeamName, TeamScore = rec.TeamScore };
                                this.MatchList[rec.GameTime].TeamData.Add(rec.TeamName, teamData);
                            }
                            if (!this.PackSetList.ContainsKey(rec.PackSet)) this.PackSetList.Add(rec.PackSet, null);
                            this.RowCount++;
                        }
                    }

                }
            }
            this.EventSync();
            this.SeriesSync(this.eventCurrent.id, this.SeriesList);
            this.TeamsSync(this.eventCurrent.id, this.TeamList);
            this.PlayersSync(this.eventCurrent.id, this.PlayerList);
            this.PackSetSync(this.eventCurrent.id, this.PackSetList);
            this.MatchSync(this.eventCurrent.id);

            StatusChange("Making a second pass to import Player Data");

            for (int irow = 0; irow <= sheet.LastRowNum; irow++)
            {
                IRow row = sheet.GetRow(irow);
                iRowCount++;
                if ((irow > 0) && (irow % 100 == 0)) StatusChange("2nd Pass: Processed " + irow.ToString() + " out of " + sheet.LastRowNum.ToString());

                if (row != null)
                {
                    if (irow == 0)
                    {
                        dictHeaders = HeadersToDict(row, out arrHeaderNames);
                        rec = new LsrXlsRec(dictHeaders, arrHeaderNames);
                    }
                    else
                    {
                        this.RecordCount++;
                        /*
                         * Note that we are not creating a new instance of this class, which means the previous values will be copied and any non-space values will be written over
                         */
                        if (rec.FromIRow(row))
                        {
                            match matchObject = MatchList[rec.GameTime].MatchObject;
                            player playerObject = PlayerList[rec.PlayerName];
                            match_player matchPlayer = matchPlayerRepo.Get(matchObject.id, playerObject.id);
                            if (matchPlayer == null)
                            {
                                matchPlayer = new match_player() { match_id = matchObject.id, player_id = playerObject.id, score = rec.Score };
                                matchPlayer = matchPlayerRepo.Insert(matchPlayer);
                            }
                            else
                            {
                                matchPlayer.score = rec.Score;
                                matchPlayerRepo.Update(matchPlayer);
                            }
                        }
                    }

                }
            }

            StatusChange("Import of data has completed!");

            bret = true;
            return bret;
        }