//------------------------------------------------------------------ //SELECIONA OS PONTOS DA MEDIA (POR RODADA) public int SelectPontosMediaRodada(ScoresInformation score) { Conexao conn = new Conexao(); String select = "SELECT * FROM tb_scores"; command = new MySqlCommand(select, conn.Conectar()); MySqlDataReader dados = command.ExecuteReader(); int pontos = 0, count = 0; while (dados.Read()) { if (Convert.ToInt32(dados["iduser"]) != Convert.ToInt32(score.IdUser)) { if (Convert.ToInt32(dados["idletter"]) == Convert.ToInt32(score.IdLetter)) { pontos += Convert.ToInt32(dados["score"]); count++; } } } if (count == 0) { count = 1; } pontos = pontos / count; conn.Conectar().Close(); return(pontos); }
//CONSULTAR PONTOS JOGADORES public MySqlDataReader ConsultarPontos(ScoresInformation score) { //ScoresInformation score = new ScoresInformation(); score.IdUser = iduser; MySqlDataReader dados = scoreDal.Select(score); return(dados); }
//INCLUIR PONTOS JOGADORES public void InserirPontos(int pontos, int indice) { ScoresInformation score = new ScoresInformation(); score.IdUser = iduser; score.Score = pontos; score.IdLetter = indice; scoreDal.Insert(score); }
//SELECT PELO USUARIO (TUDO) public MySqlDataReader Select(ScoresInformation score) { Conexao conn = new Conexao(); String select = "SELECT * FROM tb_scores WHERE iduser = " + score.IdUser; command = new MySqlCommand(select, conn.Conectar()); MySqlDataReader dados = command.ExecuteReader(); conn.Conectar().Close(); return(dados); }
public void pontuacao() { UserDal userDal = new UserDal(); ScoresDal scoreDal = new ScoresDal(); ScoresInformation score = new ScoresInformation(); //busca usuário pelo nome MySqlDataReader usuario = userDal.Select(); while (usuario.Read()) { if ((Convert.ToString(usuario["username"]) == this.usuario)) { score.IdUser = Convert.ToInt32(usuario["idUser"]); score.IdLetter = rodada; } } //busca ponto pelo id int ponto = scoreDal.SelectPontosRodada(score); //busca ponto da média int pontoMedia = scoreDal.SelectPontosMediaRodada(score); //tamanho da progressbar dinammico if (pontoMedia >= ponto) { pbMedia.Maximum = pontoMedia * 1.30; pbUsuario.Maximum = pontoMedia * 1.30; } else { pbMedia.Maximum = ponto * 1.30; pbUsuario.Maximum = ponto * 1.30; } //animação da progressbar txtPontoUsuario.Text = Convert.ToString(ponto); txtUsuario.Text = this.usuario; Duration dur = new Duration(TimeSpan.FromSeconds(10)); DoubleAnimation ani = new DoubleAnimation(ponto, dur); pbUsuario.BeginAnimation(ProgressBar.ValueProperty, ani); //animação da progressbar txtPontoMedia.Text = Convert.ToString(pontoMedia); Duration durMedia = new Duration(TimeSpan.FromSeconds(10)); DoubleAnimation aniMedia = new DoubleAnimation(pontoMedia, durMedia); pbMedia.BeginAnimation(ProgressBar.ValueProperty, aniMedia); }
//------------------------------------------------------------------ //INSERIR PONTOS public void Insert(ScoresInformation score) { Conexao conn = new Conexao(); try { //confere se usuario ja jogou antes //se sim, então deleta os pontos anteriores if (score.IdLetter == 1) { MySqlDataReader dados = Select(score); while (dados.Read()) { if (Convert.ToInt32(dados["idLetter"]) == 1) { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn.Conectar(); cmd.CommandText = "DELETE FROM tb_scores WHERE idUser ="******"INSERT INTO tb_scores(date,score,idUser,idLetter) VALUES(@data, @ponto, @usuario, @letter)"; cmd2.Parameters.AddWithValue("@data", DateTime.Now); cmd2.Parameters.AddWithValue("@ponto", score.Score); cmd2.Parameters.AddWithValue("@usuario", score.IdUser); cmd2.Parameters.AddWithValue("@letter", score.IdLetter); cmd2.ExecuteNonQuery(); } catch (MySqlException ex) { throw new Exception("Erro no Servidor: " + ex.Number); } catch (Exception ex) { throw new Exception(ex.Message); } finally { conn.Conectar().Close(); } }
//------------------------------------------------------------------ //SELECIONA TODOS OS PONTOD DO USUARIO (TODAS AS RODADAS) public int SelectPontos(ScoresInformation score) { Conexao conn = new Conexao(); String select = "SELECT * FROM tb_scores"; command = new MySqlCommand(select, conn.Conectar()); MySqlDataReader dados = command.ExecuteReader(); int pontos = 0, rodada = 0; while (dados.Read()) { if (Convert.ToInt32(dados["iduser"]) == Convert.ToInt32(score.IdUser)) { pontos += Convert.ToInt32(dados["score"]); rodada++; } } conn.Conectar().Close(); pontos = pontos / rodada; return(pontos); }
private void loadProgressbar() { ScoresInformation user = new ScoresInformation(); //user.IdUser = idUser; ScoresDal scoreDal = new ScoresDal(); /* * MySqlDataReader pontos = score.Select(); * * int i = 0; * int[] valor = new int[3]; * while (pontos.Read()) * { * valor[i] = Convert.ToInt32(pontos["score"]); * i++; * } */ int i = 0; int[] valor = new int[3]; for (i = 0; i < 3; i++) { user.IdUser = i + 1; valor[i] = scoreDal.SelectPontos(user); } Duration dur = new Duration(TimeSpan.FromSeconds(10)); DoubleAnimation ani = new DoubleAnimation(valor[0], dur); pb1.BeginAnimation(ProgressBar.ValueProperty, ani); Duration dur2 = new Duration(TimeSpan.FromSeconds(10)); DoubleAnimation ani2 = new DoubleAnimation(valor[1], dur2); pb2.BeginAnimation(ProgressBar.ValueProperty, ani2); Duration dur3 = new Duration(TimeSpan.FromSeconds(10)); DoubleAnimation ani3 = new DoubleAnimation(valor[2], dur3); pb3.BeginAnimation(ProgressBar.ValueProperty, ani3); lbl1.Content = valor[0]; lbl2.Content = valor[1]; lbl3.Content = valor[2]; //IMAGENS var uri = new Uri("pack://application:,,,/Diego.jpg"); var bitmap = new BitmapImage(uri); image1.Source = bitmap; var uri2 = new Uri("pack://application:,,,/Silvio.jpg"); var bitmap2 = new BitmapImage(uri2); image2.Source = bitmap2; var uri3 = new Uri("pack://application:,,,/Renata.jpg"); var bitmap3 = new BitmapImage(uri3); image3.Source = bitmap3; }