Exemplo n.º 1
0
        public PlayerEntryList(int tabletDeviceNumber, TableStatus tableStatus)
        {
            TabletDeviceNumber = tabletDeviceNumber;
            TabletDeviceStatus tabletDeviceStatus = AppData.TabletDeviceStatusList[tabletDeviceNumber];
            Section            section            = AppData.SectionsList.Find(x => x.SectionID == tabletDeviceStatus.SectionID);

            if (section.TabletDevicesPerTable == 1)
            {
                if (tableStatus.RoundData.NumberNorth != 0 && tableStatus.RoundData.NumberNorth != section.MissingPair)
                {
                    Add(new PlayerEntry(tableStatus.RoundData, Direction.North));
                    Add(new PlayerEntry(tableStatus.RoundData, Direction.South));
                }
                if (tableStatus.RoundData.NumberEast != 0 && tableStatus.RoundData.NumberEast != section.MissingPair)
                {
                    Add(new PlayerEntry(tableStatus.RoundData, Direction.East));
                    Add(new PlayerEntry(tableStatus.RoundData, Direction.West));
                }
            }
            else if (section.TabletDevicesPerTable == 2)
            {
                if (tabletDeviceStatus.Direction == Direction.North)
                {
                    Add(new PlayerEntry(tableStatus.RoundData, Direction.North));
                    Add(new PlayerEntry(tableStatus.RoundData, Direction.South));
                }
                else
                {
                    Add(new PlayerEntry(tableStatus.RoundData, Direction.East));
                    Add(new PlayerEntry(tableStatus.RoundData, Direction.West));
                }
            }
            else  // tabletDevicesPerTable == 4
            {
                Add(new PlayerEntry(tableStatus.RoundData, tabletDeviceStatus.Direction));
            }

            NumberOfBlankEntries = FindAll(x => x.Name == "").Count;
            ShowMessage          = section.TabletDevicesPerTable == 4 || (section.TabletDevicesPerTable == 2 && Count == 4);
        }
Exemplo n.º 2
0
        public RankingList(int tabletDeviceNumber)
        {
            TabletDeviceNumber = tabletDeviceNumber;
            TabletDeviceStatus tabletDeviceStatus = AppData.TabletDeviceStatusList[tabletDeviceNumber];

            RoundNumber = tabletDeviceStatus.RoundNumber;

            // Set player numbers to highlight appropriate rows of ranking list
            if (AppData.SectionsList.Find(x => x.SectionID == tabletDeviceStatus.SectionID).TabletDevicesPerTable == 1)
            {
                TableStatus tableStatus = AppData.TableStatusList.Find(x => x.SectionID == tabletDeviceStatus.SectionID && x.TableNumber == tabletDeviceStatus.TableNumber);
                NumberNorth = tableStatus.RoundData.NumberNorth;
                NumberEast  = tableStatus.RoundData.NumberEast;
                NumberSouth = tableStatus.RoundData.NumberSouth;
                NumberWest  = tableStatus.RoundData.NumberWest;
            }
            else  // More than one tablet device per table
            {
                // Only need to highlight one row entry, so use NumberNorth as proxy
                NumberNorth = tabletDeviceStatus.PairNumber;
            }

            using (OdbcConnection connection = new OdbcConnection(AppData.DBConnectionString))
            {
                connection.Open();
                string SQLString = $"SELECT Orientation, Number, Score, Rank FROM Results WHERE Section={tabletDeviceStatus.SectionID}";

                OdbcCommand    cmd     = new OdbcCommand(SQLString, connection);
                OdbcDataReader reader1 = null;
                try
                {
                    ODBCRetryHelper.ODBCRetry(() =>
                    {
                        reader1 = cmd.ExecuteReader();
                        while (reader1.Read())
                        {
                            Ranking ranking = new Ranking
                            {
                                Orientation = reader1.GetString(0),
                                PairNo      = reader1.GetInt32(1),
                                Score       = reader1.GetString(2),
                                Rank        = reader1.GetString(3)
                            };
                            ranking.ScoreDecimal = Convert.ToDouble(ranking.Score);
                            Add(ranking);
                        }
                    });
                }
                catch (OdbcException e)
                {
                    if (e.Errors.Count > 1 || e.Errors[0].SQLState != "42S02")  // Any error other than results table doesn't exist
                    {
                        throw (e);
                    }
                }
                finally
                {
                    reader1.Close();
                    cmd.Dispose();
                }

                if (Count == 0)  // Results table either doesn't exist or contains no entries, so try to calculate rankings
                {
                    if (AppData.IsIndividual)
                    {
                        InsertRange(0, CalculateIndividualRankingFromReceivedData(tabletDeviceStatus.SectionID));
                    }
                    else
                    {
                        InsertRange(0, CalculateRankingFromReceivedData(tabletDeviceStatus.SectionID));
                    }
                }

                // Make sure that ranking list is sorted into presentation order
                Sort((x, y) =>
                {
                    int sortValue = y.Orientation.CompareTo(x.Orientation);    // N's first then E's
                    if (sortValue == 0)
                    {
                        sortValue = y.ScoreDecimal.CompareTo(x.ScoreDecimal);
                    }
                    if (sortValue == 0)
                    {
                        sortValue = x.PairNo.CompareTo(y.PairNo);
                    }
                    return(sortValue);
                });
            }
        }
Exemplo n.º 3
0
        public MovesList(int tabletDeviceNumber, TableStatus tableStatus, int newRoundNumber, int tableNotReadyNumber)
        {
            TabletDeviceNumber = tabletDeviceNumber;
            TabletDeviceStatus tabletDeviceStatus = AppData.TabletDeviceStatusList[tabletDeviceNumber];

            Direction           = tabletDeviceStatus.Direction;
            NewRoundNumber      = newRoundNumber;
            TableNotReadyNumber = tableNotReadyNumber;
            Section section = AppData.SectionsList.Find(x => x.SectionID == tabletDeviceStatus.SectionID);

            TabletDevicesPerTable = section.TabletDevicesPerTable;
            int missingPair = section.MissingPair;

            RoundsList roundsList = new RoundsList(tabletDeviceStatus.SectionID, newRoundNumber);

            if (TabletDevicesPerTable == 1)  // tableStatus cannot be null
            {
                if (AppData.IsIndividual)
                {
                    if (tableStatus.RoundData.NumberNorth != 0)
                    {
                        Add(roundsList.GetMove(tableStatus.TableNumber, tableStatus.RoundData.NumberNorth, Direction.North));
                    }
                    if (tableStatus.RoundData.NumberSouth != 0)
                    {
                        Add(roundsList.GetMove(tableStatus.TableNumber, tableStatus.RoundData.NumberSouth, Direction.South));
                    }
                    if (tableStatus.RoundData.NumberEast != 0)
                    {
                        Add(roundsList.GetMove(tableStatus.TableNumber, tableStatus.RoundData.NumberEast, Direction.East));
                    }
                    if (tableStatus.RoundData.NumberWest != 0)
                    {
                        Add(roundsList.GetMove(tableStatus.TableNumber, tableStatus.RoundData.NumberWest, Direction.West));
                    }
                }
                else  // Not individual
                {
                    if (tableStatus.RoundData.NumberNorth != 0 && tableStatus.RoundData.NumberNorth != missingPair)
                    {
                        Add(roundsList.GetMove(tableStatus.TableNumber, tableStatus.RoundData.NumberNorth, Direction.North));
                    }
                    if (tableStatus.RoundData.NumberEast != 0 && tableStatus.RoundData.NumberEast != missingPair)
                    {
                        Add(roundsList.GetMove(tableStatus.TableNumber, tableStatus.RoundData.NumberEast, Direction.East));
                    }
                }
            }
            else  // TabletDevicesPerTable > 1, so only need move for single player/pair.  tableStatus could be null (at phantom table), so use tabletDeviceStatus
            {
                Add(roundsList.GetMove(tabletDeviceStatus.TableNumber, tabletDeviceStatus.PairNumber, Direction));
            }

            BoardsNewTable = -999;
            if (tableStatus != null)  // tableStatus==null => phantom table, so no boards to worry about
            {
                // Show boards move only to North (or North/South) unless missing, in which case only show to East (or East/West)
                LowBoard  = tableStatus.RoundData.LowBoard;
                HighBoard = tableStatus.RoundData.HighBoard;
                if (Direction == Direction.North || ((tableStatus.RoundData.NumberNorth == 0 || tableStatus.RoundData.NumberNorth == missingPair) && Direction == Direction.East))
                {
                    BoardsNewTable = roundsList.GetBoardsNewTableNumber(tableStatus.TableNumber, tableStatus.RoundData.LowBoard);
                }
            }
        }