protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.ManageRoom);
            toolbar();

            try
            {
                using (MySqlConnection sqlconn = new MySqlConnection(Resources.GetString(Resource.String.connection)))
                {
                    sqlconn.Open();
                    string queryString = "select * from Room join User on Room.MasterID = User.id" +
                                         " where Room.Id=@id";
                    MySqlCommand cmd = new MySqlCommand(queryString, sqlconn);
                    cmd.Parameters.AddWithValue("@id", Global.selectedRoomId);

                    using (MySqlDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            User master = new User(rdr.GetInt32(11), rdr.GetString(12), rdr.GetInt32(14), rdr.GetInt32(15), rdr.GetString(16));
                            thisRoom = new Room(rdr.GetInt32(0), rdr.GetInt32(3), rdr.GetString(1), rdr.GetString(2), rdr.GetString(5).Split(' ')[0], rdr.GetString(4), rdr.GetString(6), rdr.GetString(9), rdr.GetBoolean(7), rdr.GetBoolean(8), "img", master);
                        }
                        rdr.Close();
                    }

                    string       queryString2 = "select User.id,Username,`Master reputation`,`Player reputation`,`Last seen`,accept from UserInRoom join User on UserId=User.id where RoomId = @id";
                    MySqlCommand cmd2         = new MySqlCommand(queryString2, sqlconn);
                    cmd2.Parameters.AddWithValue("@id", Global.selectedRoomId);

                    using (MySqlDataReader rdr = cmd2.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            usersInRoom.Add(new User(rdr.GetInt32(0), rdr.GetString(1), rdr.GetInt32(2), rdr.GetInt32(3), rdr.GetString(4)));
                            usersInRoom.Last().AcceptInThisRoom = rdr.GetBoolean(5);
                        }
                        rdr.Close();
                    }
                    thisRoom.CurrentPlayerNumber = usersInRoom.Count();
                    sqlconn.Close();
                }

                ListView playerListView = FindViewById <ListView>(Resource.Id.playerListView);

                PlayersListView listAdapter = new PlayersListView(usersInRoom, this);
                playerListView.Adapter    = listAdapter;
                playerListView.ItemClick += PlayerSelected;
            }
            catch (Exception ex)
            {
                AlertDialog.Builder connectionException = new AlertDialog.Builder(this);
                connectionException.SetTitle("Connection Error");
                connectionException.SetMessage(ex.ToString());
                connectionException.SetNegativeButton("Return", delegate { });
                connectionException.Create();
                connectionException.Show();
            }
        }
Exemple #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.SelectedRoom);
            toolbar();

            try
            {
                using (MySqlConnection sqlconn = new MySqlConnection(Resources.GetString(Resource.String.connection)))
                {
                    sqlconn.Open();
                    string queryString = "select * from Room join User on Room.MasterID = User.id" +
                                         " where Room.Id=@id";
                    MySqlCommand cmd = new MySqlCommand(queryString, sqlconn);
                    cmd.Parameters.AddWithValue("@id", Global.selectedRoomId);

                    using (MySqlDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            User master = new User(rdr.GetInt32(11), rdr.GetString(12), rdr.GetInt32(14), rdr.GetInt32(15), rdr.GetString(16));
                            thisRoom = new Room(rdr.GetInt32(0), rdr.GetInt32(3), rdr.GetString(1), rdr.GetString(2), rdr.GetString(5).Split(' ')[0], rdr.GetString(4), rdr.GetString(6), rdr.GetString(9), rdr.GetBoolean(7), rdr.GetBoolean(8), "img", master);
                        }
                        rdr.Close();
                    }

                    string       queryString2 = "select User.id,Username,`Master reputation`,`Player reputation`,`Last seen` from UserInRoom join User on UserId=User.id where accept='1' AND RoomId = @id";
                    MySqlCommand cmd2         = new MySqlCommand(queryString2, sqlconn);
                    cmd2.Parameters.AddWithValue("@id", Global.selectedRoomId);

                    using (MySqlDataReader rdr = cmd2.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            usersInRoom.Add(new User(rdr.GetInt32(0), rdr.GetString(1), rdr.GetInt32(2), rdr.GetInt32(3), rdr.GetString(4)));
                            if (Global.logIn)
                            {
                                if (Global.activeUser.Id == usersInRoom.Last().Id)
                                {
                                    activeUserInRoom = true;
                                }
                            }
                        }
                        rdr.Close();
                    }
                    thisRoom.CurrentPlayerNumber = usersInRoom.Count();
                    sqlconn.Close();
                }
                TextView txtName      = FindViewById <TextView>(Resource.Id.txtName);
                TextView txtSystem    = FindViewById <TextView>(Resource.Id.txtSystem);
                TextView txtCity      = FindViewById <TextView>(Resource.Id.txtCity);
                TextView txtDate      = FindViewById <TextView>(Resource.Id.txtDate);
                TextView txtDesc      = FindViewById <TextView>(Resource.Id.txtDesc);
                TextView txtNOPlayers = FindViewById <TextView>(Resource.Id.txtNOPlayers);
                TextView txtMaster    = FindViewById <TextView>(Resource.Id.txtMaster);

                txtName.Text      = thisRoom.Name;
                txtSystem.Text    = thisRoom.System;
                txtCity.Text      = thisRoom.City1;
                txtDate.Text      = string.Format("{0} {1}", thisRoom.Date1, thisRoom.Time1);
                txtDesc.Text      = thisRoom.Desc1;
                txtNOPlayers.Text = string.Format("{0}/{1}", thisRoom.CurrentPlayerNumber, thisRoom.NOPlayers1);
                txtMaster.Text    = thisRoom.Master1.Username;
                txtMaster.Click  += masterClick;

                ListView playerListView = FindViewById <ListView>(Resource.Id.playerListView);

                PlayersListView listAdapter = new PlayersListView(usersInRoom, this);
                playerListView.Adapter    = listAdapter;
                playerListView.ItemClick += PlayerSelected;
            }
            catch (Exception ex)
            {
                AlertDialog.Builder connectionException = new AlertDialog.Builder(this);
                connectionException.SetTitle("Connection Error");
                connectionException.SetMessage(ex.ToString());
                connectionException.SetNegativeButton("Return", delegate { });
                connectionException.Create();
                connectionException.Show();
            }
        }