private void UpdatePlayerPickers(object sender, int playerNumber)
        {
            Picker tmpPicker = (Picker)sender;

            if (tmpPicker.SelectedIndex < 0)
            {
                return;
            }

            Picker pckPlayer;

            if (playerNumber == 1)
            {
                pckPlayer = pckPlayer1;
            }
            else
            {
                pckPlayer = pckPlayer2;
            }

            if (playerNumber == 1)
            {
                pckPlayer.SelectedIndexChanged -= pckPlayer1_SelectedIndexChanged;
            }
            else
            {
                pckPlayer.SelectedIndexChanged -= pckPlayer2_SelectedIndexChanged;
            }

            clsPlayerInfo otherPlayer = (clsPlayerInfo)pckPlayer.SelectedItem;
            clsPlayerInfo thisPlayer  = (clsPlayerInfo)tmpPicker.SelectedItem;

            pckPlayer.ItemsSource = lstPlayers.OrderBy(obj => obj.PlayerName).AsQueryable().Where(o => o.PlayerId != thisPlayer.PlayerId).ToList();

            int intIndex = -1;

            foreach (clsPlayerInfo item in pckPlayer.ItemsSource)
            {
                intIndex++;
                if (item.PlayerId == otherPlayer.PlayerId)
                {
                    pckPlayer.SelectedIndex = intIndex;
                    break;
                }
            }

            if (playerNumber == 1)
            {
                pckPlayer.SelectedIndexChanged += pckPlayer1_SelectedIndexChanged;
            }
            else
            {
                pckPlayer.SelectedIndexChanged += pckPlayer2_SelectedIndexChanged;
            }
        }
        private void saveButton_Clicked(object sender, EventArgs e)
        {
            clsPlayerInfo player1 = (clsPlayerInfo)pckPlayer1.SelectedItem;
            clsPlayerInfo player2 = (clsPlayerInfo)pckPlayer2.SelectedItem;


            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.DB_PATH))
            {
                TournamentMainRoundTable tmpOtherTable;
                TournamentMainRoundTable tmpCurrentTable;
                clsPlayerInfo            tmpPlayer;
                int tmpPlayerId;

                for (int i = 1; i <= 2; i++)
                {
                    if (i == 1)
                    {
                        tmpPlayer   = player1;
                        tmpPlayerId = intPlayer1Id;
                    }

                    else
                    {
                        tmpPlayer   = player2;
                        tmpPlayerId = intPlayer2Id;
                    }

                    if (tmpPlayer.PlayerId != tmpPlayerId)
                    {
                        tmpOtherTable   = new TournamentMainRoundTable();
                        tmpCurrentTable = new TournamentMainRoundTable();

                        TournamentMainRoundTable otherTable = conn.Get <TournamentMainRoundTable>(tmpPlayer.TableId);

                        tmpOtherTable.Player1Id   = otherTable.Player1Id;
                        tmpOtherTable.Player1Name = otherTable.Player1Name;
                        tmpOtherTable.Player2Id   = otherTable.Player2Id;
                        tmpOtherTable.Player2Name = otherTable.Player2Name;

                        tmpCurrentTable.Player1Id   = currentTable.Player1Id;
                        tmpCurrentTable.Player1Name = currentTable.Player1Name;
                        tmpCurrentTable.Player2Id   = currentTable.Player2Id;
                        tmpCurrentTable.Player2Name = currentTable.Player2Name;

                        if (otherTable.Player1Id == tmpPlayer.PlayerId)
                        {
                            otherTable.Player1Id   = tmpCurrentTable.Player1Id;
                            otherTable.Player1Name = tmpCurrentTable.Player1Name;
                            otherTable.TableName   = string.Format("{0} vs {1}", otherTable.Player1Name, otherTable.Player2Name);

                            currentTable.Player1Id   = tmpOtherTable.Player1Id;
                            currentTable.Player1Name = tmpOtherTable.Player1Name;
                            currentTable.TableName   = string.Format("{0} vs {1}", currentTable.Player1Name, currentTable.Player2Name);
                        }
                        else if (otherTable.Player2Id == tmpPlayer.PlayerId)
                        {
                            otherTable.Player2Id   = tmpCurrentTable.Player1Id;
                            otherTable.Player2Name = tmpCurrentTable.Player1Name;
                            otherTable.TableName   = string.Format("{0} vs {1}", otherTable.Player1Name, otherTable.Player2Name);

                            currentTable.Player1Id   = tmpOtherTable.Player2Id;
                            currentTable.Player1Name = tmpOtherTable.Player2Name;
                            currentTable.TableName   = string.Format("{0} vs {1}", currentTable.Player1Name, currentTable.Player2Name);
                        }

                        conn.Update(otherTable);
                        conn.Update(currentTable);
                    }
                }

                //if (player1.PlayerId != intPlayer1Id)
                //{
                //    tmpTable = new TournamentMainRoundTable();

                //    TournamentMainRoundTable otherTable = conn.Get<TournamentMainRoundTable>(player1.TableId);

                //    tmpTable = otherTable;

                //    if (otherTable.Player1Id == player1.PlayerId)
                //    {
                //        otherTable.Player1Id = currentTable.Player1Id;
                //        otherTable.Player1Name = currentTable.Player1Name;
                //        otherTable.TableName = string.Format("{0} vs {1}", otherTable.Player1Name, otherTable.Player2Name);

                //        currentTable.Player1Id = tmpTable.Player1Id;
                //        currentTable.Player1Name = tmpTable.Player1Name;
                //        currentTable.TableName = string.Format("{0} vs {1}", currentTable.Player1Name, currentTable.Player2Name);
                //    }
                //    else if (otherTable.Player2Id == player1.PlayerId)
                //    {
                //        otherTable.Player2Id = currentTable.Player1Id;
                //        otherTable.Player2Name = currentTable.Player1Name;
                //        otherTable.TableName = string.Format("{0} vs {1}", otherTable.Player1Name, otherTable.Player2Name);

                //        currentTable.Player1Id = tmpTable.Player2Id;
                //        currentTable.Player1Name = tmpTable.Player2Name;
                //        currentTable.TableName = string.Format("{0} vs {1}", currentTable.Player1Name, currentTable.Player2Name);
                //    }
                //}

                //if (player2.PlayerId != intPlayer2Id)
                //{
                //    tmpTable = new TournamentMainRoundTable();

                //    TournamentMainRoundTable otherTable = conn.Get<TournamentMainRoundTable>(player2.TableId);

                //    tmpTable = otherTable;

                //    if (otherTable.Player1Id == player2.PlayerId)
                //    {
                //        otherTable.Player1Id = currentTable.Player1Id;
                //        otherTable.Player1Name = currentTable.Player1Name;
                //        otherTable.TableName = string.Format("{0} vs {1}", otherTable.Player1Name, otherTable.Player2Name);

                //        currentTable.Player1Id = tmpTable.Player1Id;
                //        currentTable.Player1Name = tmpTable.Player1Name;
                //        currentTable.TableName = string.Format("{0} vs {1}", currentTable.Player1Name, currentTable.Player2Name);
                //    }
                //    else if (otherTable.Player2Id == player2.PlayerId)
                //    {
                //        otherTable.Player2Id = currentTable.Player1Id;
                //        otherTable.Player2Name = currentTable.Player1Name;
                //        otherTable.TableName = string.Format("{0} vs {1}", otherTable.Player1Name, otherTable.Player2Name);

                //        currentTable.Player1Id = tmpTable.Player2Id;
                //        currentTable.Player1Name = tmpTable.Player2Name;
                //        currentTable.TableName = string.Format("{0} vs {1}", currentTable.Player1Name, currentTable.Player2Name);
                //    }
                //}
            }

            Navigation.PopAsync();
        }
        private void saveButton_Clicked(object sender, EventArgs e)
        {
            clsPlayerInfo player1 = (clsPlayerInfo)pckPlayer1.SelectedItem;
            clsPlayerInfo player2 = (clsPlayerInfo)pckPlayer2.SelectedItem;

            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.DB_PATH))
            {
                TournamentMainRoundTable tmpOtherTable;
                TournamentMainRoundTable tmpCurrentTable;
                clsPlayerInfo            tmpPlayer;
                int tmpPlayerId;

                //Go through each Picker set of players
                for (int i = 1; i <= 2; i++)
                {
                    if (i == 1)
                    {
                        tmpPlayer   = player1;
                        tmpPlayerId = intPlayer1Id;
                    }
                    else
                    {
                        tmpPlayer   = player2;
                        tmpPlayerId = intPlayer2Id;
                    }

                    //If the currently selected player is not the same player that was loaded, proceed
                    if (tmpPlayer.PlayerId != tmpPlayerId)
                    {
                        tmpOtherTable   = new TournamentMainRoundTable();
                        tmpCurrentTable = new TournamentMainRoundTable();

                        TournamentMainRoundTable otherTable = conn.Get <TournamentMainRoundTable>(tmpPlayer.TableId);

                        //Ensure we're not swamping player spots within the same table.  If so, can create issues with this logic that there's really no need to code for at this point.
                        if (otherTable.Id != currentTable.Id)
                        {
                            //Set local temp object properties instead of copying the objects themselves, preventing inadvertently changing table data unintentionally
                            tmpOtherTable.Player1Id   = otherTable.Player1Id;
                            tmpOtherTable.Player1Name = otherTable.Player1Name;
                            tmpOtherTable.Player2Id   = otherTable.Player2Id;
                            tmpOtherTable.Player2Name = otherTable.Player2Name;

                            tmpCurrentTable.Player1Id   = currentTable.Player1Id;
                            tmpCurrentTable.Player1Name = currentTable.Player1Name;
                            tmpCurrentTable.Player2Id   = currentTable.Player2Id;
                            tmpCurrentTable.Player2Name = currentTable.Player2Name;

                            //Find player being swapped with on the other tableId, determine if player 1 or 2, keeping in mind if the current table's player is player 1 or 2 already
                            //(that way we can swap a player 1 from one table to a player 2 on another table)
                            if (tmpOtherTable.Player1Id == tmpPlayer.PlayerId)
                            {
                                if (i == 1)
                                {
                                    currentTable.Player1Id   = tmpOtherTable.Player1Id;
                                    currentTable.Player1Name = tmpOtherTable.Player1Name;
                                    otherTable.Player1Id     = tmpCurrentTable.Player1Id;
                                    otherTable.Player1Name   = tmpCurrentTable.Player1Name;
                                }
                                else
                                {
                                    currentTable.Player2Id   = tmpOtherTable.Player1Id;
                                    currentTable.Player2Name = tmpOtherTable.Player1Name;
                                    otherTable.Player1Id     = tmpCurrentTable.Player2Id;
                                    otherTable.Player1Name   = tmpCurrentTable.Player2Name;
                                }
                            }
                            else if (tmpOtherTable.Player2Id == tmpPlayer.PlayerId)
                            {
                                if (i == 1)
                                {
                                    currentTable.Player1Id   = tmpOtherTable.Player2Id;
                                    currentTable.Player1Name = tmpOtherTable.Player2Name;
                                    otherTable.Player2Id     = tmpCurrentTable.Player1Id;
                                    otherTable.Player2Name   = tmpCurrentTable.Player1Name;
                                }
                                else
                                {
                                    currentTable.Player2Id   = tmpOtherTable.Player2Id;
                                    currentTable.Player2Name = tmpOtherTable.Player2Name;
                                    otherTable.Player2Id     = tmpCurrentTable.Player2Id;
                                    otherTable.Player2Name   = tmpCurrentTable.Player2Name;
                                }
                            }

                            //Reset the tables' names
                            currentTable.TableName = string.Format("{0} vs {1}", currentTable.Player1Name, currentTable.Player2Name);
                            otherTable.TableName   = string.Format("{0} vs {1}", otherTable.Player1Name, otherTable.Player2Name);
                        }

                        //Update the tables' information on the database
                        conn.Update(otherTable);
                        conn.Update(currentTable);
                    }
                }
            }

            Navigation.PopAsync();
        }