Exemplo n.º 1
0
 void OnRandButtonClicked(object sender, EventArgs e)
 {
     GetIds();
     using (var connection = new SQLiteConnection(dbName))
     {
         Scorelem scorelem;
         scorelem = new Scorelem
         {
             Id = 0
         };
         Switch jocDublu              = FindViewById <Switch>(Resource.Id.jocDublu);
         IEnumerable <Player> pl      = connection.Query <Player>("select * from player order by id");
         List <Player>        players = pl.ToList <Player>();
         int actPlayer = getActPlayer(pl);
         if (actPlayer == nPlayer - 1)
         {
             actPlayer = 0;
         }
         else
         {
             actPlayer += 1;
         }
         int  iPlayer = 0;
         bool notNull = false;
         foreach (Player player in pl)
         {
             player.Active = (actPlayer == iPlayer);
             setActPlayer(iPlayer, player);
             EditText score   = FindViewById <EditText>(ps[iPlayer]);
             Button   atout   = FindViewById <Button>(pa[iPlayer]);
             Button   inchide = FindViewById <Button>(pi[iPlayer]);
             player.Atout  = (atout.Text == "X");
             player.Dublu  = jocDublu.Checked;
             player.Inchis = (inchide.Text == "X");
             int j = 0;
             if (Int32.TryParse(score.Text, out j))
             {
             }
             if (inchide.Text == "X")
             {
                 j += 100;
             }
             if (jocDublu.Checked)
             {
                 j += j;
             }
             if (atout.Text == "X")
             {
                 j += 50;
             }
             player.Score  = j;
             player.Total += j;
             if (j != 0)
             {
                 notNull = true;
             }
             connection.Update(player);
             if (iPlayer == 0)
             {
                 scorelem.Score1 = player.Score.ToString();
             }
             if (iPlayer == 1)
             {
                 scorelem.Score2 = player.Score.ToString();
             }
             if (iPlayer == 2)
             {
                 scorelem.Score3 = player.Score.ToString();
             }
             if (iPlayer == 3)
             {
                 scorelem.Score4 = player.Score.ToString();
             }
             iPlayer++;
             if (inchide.Text == "X")
             {
                 scorelem.Inchide = iPlayer.ToString();
             }
         }
         if (notNull)
         {
             Button corButton = FindViewById <Button>(Resource.Id.buttonCor);
             corButton.Visibility = ViewStates.Visible;
             connection.Insert(scorelem);
         }
     }
     fillScreen("N");
 }
Exemplo n.º 2
0
        void OnStartButtonClicked(object sender, EventArgs e)
        {
            int[] jc = new int[4];
            jc[0] = Resource.Id.Jocatorul1; jc[1] = Resource.Id.Jocatorul2; jc[2] = Resource.Id.Jocatorul3; jc[3] = Resource.Id.Jocatorul4;
            string folder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            string dbname = System.IO.Path.Combine(folder, "players.db");

            System.IO.File.Delete(dbname);
            using (var connection = new SQLiteConnection(dbname))
            {
                Player   player;
                Scorelem scorelem;
                try
                {
                    connection.CreateTable <Player>();
                    connection.CreateTable <Scorelem>();
                }
                catch (SQLiteException ex)
                {
                    Log.Info("SQLiteEx", ex.Message);
                    return;
                }
                int nPlayers = 0;
                for (int i = 0; i < 4; i++)
                {
                    EditText joc = FindViewById <EditText>(jc[i]);
                    if (joc.Text != "")
                    {
                        nPlayers++;
                    }
                }
                scorelem = new Scorelem
                {
                    Id = 0
                };
                for (int i = 0; i < nPlayers; i++)
                {
                    EditText joc = FindViewById <EditText>(jc[i]);
                    player = new Player
                    {
                        Name   = joc.Text,
                        Id     = i + 1,
                        Score  = 0,
                        Atout  = false,
                        Active = false,
                        Inchis = false
                    };
                    if (i == 0)
                    {
                        player.Active = true;
                    }
                    if (i == 0)
                    {
                        scorelem.Score1 = joc.Text;
                    }
                    if (i == 1)
                    {
                        scorelem.Score2 = joc.Text;
                    }
                    if (i == 2)
                    {
                        scorelem.Score3 = joc.Text;
                    }
                    if (i == 3)
                    {
                        scorelem.Score4 = joc.Text;
                    }
                    connection.Insert(player);
                }
                connection.Insert(scorelem);
            }
            Intent intent = new Intent(this, typeof(Scores));

            StartActivity(intent);
        }