예제 #1
0
파일: Bid.cs 프로젝트: pjflip/TabPlay
        public void UpdateDB(int deviceNumber, int boardNumber)
        {
            Device device = AppData.DeviceList[deviceNumber];
            string dbBid;

            if (PassCount > 0)
            {
                dbBid = "PASS";
            }
            else if (LastBidX != "")
            {
                dbBid = LastBidX;
            }
            else
            {
                dbBid = LastBidLevel.ToString() + LastBidSuit;
            }

            using (OdbcConnection connection = new OdbcConnection(AppData.DBConnectionString))
            {
                connection.Open();
                // Delete any spurious previously made bids
                string      SQLString = $"DELETE FROM BiddingData WHERE Section={device.SectionID} AND [Table]={device.TableNumber} AND Round={device.RoundNumber} AND Board={boardNumber} AND Counter={BidCounter}";
                OdbcCommand cmd       = new OdbcCommand(SQLString, connection);
                try
                {
                    ODBCRetryHelper.ODBCRetry(() =>
                    {
                        cmd.ExecuteNonQuery();
                    });
                }
                finally
                {
                    cmd.Dispose();
                }

                SQLString = $"INSERT INTO BiddingData (Section, [Table], Round, Board, Counter, Direction, Bid, DateLog, TimeLog) VALUES ({device.SectionID}, {device.TableNumber}, {device.RoundNumber}, {boardNumber}, {BidCounter}, '{LastCallDirection.Substring(0, 1)}', '{dbBid}', #{DateTime.Now:yyyy-MM-dd}#, #{DateTime.Now:yyyy-MM-dd hh:mm:ss}#)";
                cmd       = new OdbcCommand(SQLString, connection);
                try
                {
                    ODBCRetryHelper.ODBCRetry(() =>
                    {
                        cmd.ExecuteNonQuery();
                    });
                }
                finally
                {
                    cmd.Dispose();
                }

                if (BidCounter == 0)
                {
                    // Update table status in database
                    SQLString = $"UPDATE Tables SET BiddingStarted=True WHERE Section={device.SectionID} AND [Table]={device.TableNumber}";
                    cmd       = new OdbcCommand(SQLString, connection);
                    try
                    {
                        ODBCRetryHelper.ODBCRetry(() =>
                        {
                            cmd.ExecuteNonQuery();
                        });
                    }
                    finally
                    {
                        cmd.Dispose();
                    }
                }
            }
        }
예제 #2
0
        public Bidding(int deviceNumber, Table table)
        {
            DeviceNumber = deviceNumber;
            Device device = AppData.DeviceList[deviceNumber];

            BoardNumber = table.BoardNumber;
            Direction   = device.Direction;
            int directionNumber = Utilities.DirectionToNumber(Direction);

            PairNumber   = table.PairNumber[directionNumber];
            PlayerName   = table.PlayerName[directionNumber];
            NSVulnerable = Utilities.NSVulnerability[(BoardNumber - 1) % 16];
            EWVulnerable = Utilities.EWVulnerability[(BoardNumber - 1) % 16];
            BidTable     = new string[10, 4];
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    BidTable[i, j] = "";
                }
            }
            LastCallDirection = "";
            LastBidLevel      = 0;
            LastBidSuit       = "";
            LastBidX          = "";
            LastBidDirection  = "";
            PassCount         = 0;
            BidCounter        = -1;
            ToBidDirection    = "";
            PollInterval      = Settings.PollInterval;
            if (AppData.IsIndividual)
            {
                PairOrPlayer = "Player";
            }
            else
            {
                PairOrPlayer = "Pair";
            }
            List <DatabaseBid> databaseBidList = new List <DatabaseBid>();

            using (OdbcConnection connection = new OdbcConnection(AppData.DBConnectionString))
            {
                connection.Open();
                Utilities.CheckTabPlayPairNos(connection);
                string         SQLString = $"SELECT Counter, Bid, Direction FROM BiddingData WHERE Section={device.SectionID} AND Table={device.TableNumber} AND Round={device.RoundNumber} AND Board={BoardNumber}";
                OdbcCommand    cmd       = new OdbcCommand(SQLString, connection);
                OdbcDataReader reader    = null;
                try
                {
                    ODBCRetryHelper.ODBCRetry(() =>
                    {
                        reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            int tempCounter         = reader.GetInt32(0);
                            string tempBid          = reader.GetString(1);
                            string tempDirection    = reader.GetString(2);
                            DatabaseBid databaseBid = new DatabaseBid
                            {
                                Counter   = tempCounter,
                                Bid       = tempBid,
                                Direction = tempDirection
                            };
                            databaseBidList.Add(databaseBid);
                        }
                    });
                }
                finally
                {
                    reader.Close();
                    cmd.Dispose();
                }
            }

            databaseBidList.Sort((x, y) => x.Counter.CompareTo(y.Counter));
            foreach (DatabaseBid databaseBid in databaseBidList)
            {
                BidCounter = databaseBid.Counter;
                if (databaseBid.Direction == "N")
                {
                    LastCallDirection = "North";
                    ToBidDirection    = "East";
                }
                else if (databaseBid.Direction == "E")
                {
                    LastCallDirection = "East";
                    ToBidDirection    = "South";
                }
                else if (databaseBid.Direction == "S")
                {
                    LastCallDirection = "South";
                    ToBidDirection    = "West";
                }
                else if (databaseBid.Direction == "W")
                {
                    LastCallDirection = "West";
                    ToBidDirection    = "North";
                }
                if (databaseBid.Bid == "PASS")
                {
                    PassCount++;
                    BidTable[BidCounter / 4, BidCounter % 4] = "<span style='color:darkgreen'>Pass</span>";
                }
                else if (databaseBid.Bid == "x")
                {
                    PassCount = 0;
                    BidTable[BidCounter / 4, BidCounter % 4] = "<span style='color:darkred'>X</span>";
                    LastBidX         = "x";
                    LastBidDirection = LastCallDirection;
                }
                else if (databaseBid.Bid == "xx")
                {
                    PassCount = 0;
                    BidTable[BidCounter / 4, BidCounter % 4] = "<span style='color:darkblue'>XX</span>";
                    LastBidX         = "xx";
                    LastBidDirection = LastCallDirection;
                }
                else
                {
                    LastBidLevel     = Convert.ToInt32(databaseBid.Bid.Substring(0, 1));
                    LastBidX         = "";
                    LastBidDirection = LastCallDirection;
                    LastBidSuit      = databaseBid.Bid.Substring(1);
                    if (LastBidSuit == "S")
                    {
                        BidTable[BidCounter / 4, BidCounter % 4] = LastBidLevel.ToString() + "<span style='color:black'>&spades;</span>";
                    }
                    else if (LastBidSuit == "H")
                    {
                        BidTable[BidCounter / 4, BidCounter % 4] = LastBidLevel.ToString() + "<span style='color:red'>&hearts;</span>";
                    }
                    else if (LastBidSuit == "D")
                    {
                        BidTable[BidCounter / 4, BidCounter % 4] = LastBidLevel.ToString() + "<span style='color:orangered'>&diams;</span>";
                    }
                    else if (LastBidSuit == "C")
                    {
                        BidTable[BidCounter / 4, BidCounter % 4] = LastBidLevel.ToString() + "<span style='color:darkblue'>&clubs;</span>";
                    }
                    else
                    {
                        BidTable[BidCounter / 4, BidCounter % 4] = LastBidLevel.ToString() + "NT";
                    }
                }
            }

            HandRecord handRecord = HandRecords.HandRecordsList.Find(x => x.SectionID == device.SectionID && x.BoardNumber == BoardNumber);

            if (handRecord == null)     // Can't find matching hand record, so use default SectionID = 1
            {
                handRecord = HandRecords.HandRecordsList.Find(x => x.SectionID == 1 && x.BoardNumber == BoardNumber);
            }
            CardString  = handRecord.HandRow(device.Direction);
            DisplayRank = new string[13];
            DisplaySuit = new string[13];
            for (int i = 0; i < 13; i++)
            {
                DisplayRank[i] = Utilities.DisplayRank(CardString[i]);
                DisplaySuit[i] = Utilities.DisplaySuit(CardString[i]);
            }
            Dealer = handRecord.Dealer;

            BidDirections = new string[4];
            int northDirectionNumber = (4 - Utilities.DirectionToNumber(Dealer)) % 4;

            BidDirections[northDirectionNumber]           = "North";
            BidDirections[(northDirectionNumber + 1) % 4] = "East";
            BidDirections[(northDirectionNumber + 2) % 4] = "South";
            BidDirections[(northDirectionNumber + 3) % 4] = "West";

            if (ToBidDirection == "")
            {
                ToBidDirection = Dealer;
            }

            // Set table info
            table.LastBid = new Bid(LastCallDirection, LastBidLevel, LastBidSuit, LastBidX, false, LastBidDirection, PassCount, BidCounter);
        }