Beispiel #1
0
 public static void Insert(Modelo.Jogo jogo)
 {
     try
     {
         if (Select(jogo.id) == null)
         {
             using (connection = new SqlConnection(connectionString))
             {
                 connection.Open();
                 string     sqlJogo = "INSERT INTO Jogo(jogoUrl, descricao, imagemUrl, nome) VALUES (@jogoUrl, @descricao, @imagemUrl, @nome)";
                 SqlCommand cmdJogo = new SqlCommand(sqlJogo, connection);
                 cmdJogo.Parameters.AddWithValue("@jogoUrl", jogo.jogoUrl);
                 cmdJogo.Parameters.AddWithValue("@descricao", jogo.descricao);
                 cmdJogo.Parameters.AddWithValue("@imagemUrl", jogo.imagemUrl);
                 cmdJogo.Parameters.AddWithValue("@nome", jogo.nome);
                 cmdJogo.ExecuteNonQuery();
             }
         }
         else
         {
             Update(jogo);
         }
     }
     catch (SystemException)
     {
         throw;
     }
 }
Beispiel #2
0
        protected void addGame_Click(object sender, EventArgs e)
        {
            uploadGame();
            uploadImage();
            Modelo.Jogo jog = new Modelo.Jogo("..\\Download\\" + UploadGame.FileName, TextBox1.Text, "..\\Images\\" + UploadImage.FileName, TextBox2.Text);
            DAL.DALGames.Insert(jog);

            this.jogocategoria = new Modelo.JogoCategoria(DAL.DALGames.SelectByName(jog.nome).id, DAL.DALCategories.SelectByDescription("Download").id);
            DAL.DALGamesCategories.Insert(this.jogocategoria);

            Response.Redirect("~/Administrador/Index.aspx");
        }
Beispiel #3
0
        //excluir jogo
        protected void Confirmar_Click(object sender, EventArgs e)
        {
            string JogoUrl   = this.jogo.jogoUrl;
            string descricao = this.jogo.descricao;
            string imagemUrl = this.jogo.imagemUrl;
            string nome      = this.jogo.nome;

            DAL.DALGames daljogo = new DAL.DALGames();
            Modelo.Jogo  jogo    = new Modelo.Jogo(JogoUrl, descricao, imagemUrl, nome);
            DAL.DALGames.Delete(jogo);

            Response.Redirect("~/Administrador/Index.aspx");
        }
Beispiel #4
0
        protected void addGame_Click(object sender, EventArgs e)
        {
            if (Categorias.SelectedItem.Value != "Escolha uma categoria")
            {
                //uploadGame();
                uploadImage();
                DAL.DALGames jogo = new DAL.DALGames();
                Modelo.Jogo  jog  = new Modelo.Jogo(JogoUrl.Text, TextBox1.Text, this.imagem, TextBox2.Text, "..\\Images\\" + UploadImage.FileName);
                DAL.DALGames.Insert(jog);
                this.jogocategoria = new Modelo.JogoCategoria(DAL.DALGames.SelectByName(jog.nome).id, int.Parse(Categorias.SelectedItem.Value));
                DAL.DALGamesCategories.Insert(this.jogocategoria);

                Response.Redirect("~/Administrador/Index.aspx");
            }
            Response.Redirect("~/Administrador/Index.aspx");
        }
Beispiel #5
0
 public static void Delete(Modelo.Jogo jogo)
 {
     try
     {
         using (connection = new SqlConnection(connectionString))
         {
             connection.Open();
             string     sqlJogo = "DELETE FROM Jogo WHERE id = @id";
             SqlCommand cmdJogo = new SqlCommand(sqlJogo, connection);
             cmdJogo.Parameters.AddWithValue("@id", jogo.id);
             cmdJogo.ExecuteNonQuery();
         }
     }
     catch (SystemException)
     {
         throw;
     }
 }
Beispiel #6
0
        public static List <Modelo.Jogo> SelectAll()
        {
            Modelo.Jogo        jogo  = null;
            List <Modelo.Jogo> jogos = new List <Modelo.Jogo>();

            try
            {
                using (connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    string        sqlJogos = "SELECT * FROM Jogo";
                    SqlCommand    cmdJogos = new SqlCommand(sqlJogos, connection);
                    SqlDataReader drJogos;

                    using (drJogos = cmdJogos.ExecuteReader())
                    {
                        if (drJogos.HasRows)
                        {
                            while (drJogos.Read())
                            {
                                int    idJogo    = (int)drJogos["id"];
                                string jogoUrl   = (string)drJogos["jogoUrl"];
                                string descricao = (string)drJogos["descricao"];
                                string imagemUrl = (string)drJogos["imagemUrl"];
                                string nome      = (string)drJogos["nome"];
                                jogo = new Modelo.Jogo(idJogo, jogoUrl, descricao, imagemUrl, nome);
                                jogos.Add(jogo);
                            }
                        }
                    }
                }
            }
            catch (SystemException)
            {
                throw;
            }

            return(jogos);
        }
Beispiel #7
0
 public static Modelo.Jogo SelectByName(string jogo_nome)
 {
     //instancia um novo usuario
     Modelo.Jogo jogo = null;
     try
     {
         using (connection = new SqlConnection(connectionString))
         {
             //abre a conexão
             connection.Open();
             string     sqlJogo = "SELECT * FROM Jogo WHERE nome = @nome";
             SqlCommand cmdJogo = new SqlCommand(sqlJogo, connection);
             cmdJogo.Parameters.AddWithValue("@nome", jogo_nome);
             SqlDataReader drJogo;
             using (drJogo = cmdJogo.ExecuteReader())
             {
                 if (drJogo.HasRows)
                 {
                     //lê os resultados
                     while (drJogo.Read())
                     {
                         int    idJogo    = (int)drJogo["id"];
                         string jogoUrl   = (string)drJogo["jogoUrl"];
                         string descricao = (string)drJogo["descricao"];
                         string imagemUrl = (string)drJogo["imagemUrl"];
                         string nome      = (string)drJogo["nome"];
                         jogo = new Modelo.Jogo(idJogo, jogoUrl, descricao, imagemUrl, nome);
                     }
                 }
             }
         }
     }
     catch (SystemException)
     {
         throw;
     }
     return(jogo);
 }
Beispiel #8
0
 public static void Update(Modelo.Jogo jogo)
 {
     try
     {
         using (connection = new SqlConnection(connectionString))
         {
             connection.Open();
             if (Select(jogo.id) != jogo)
             {
                 string     sqlJogo = "UPDATE Carrinho SET descricao = @descricao, nome = @nome, imagemUrl = @imagemUrl WHERE id = @id";
                 SqlCommand cmdJogo = new SqlCommand(sqlJogo, connection);
                 cmdJogo.Parameters.AddWithValue("@descricao", jogo.descricao);
                 cmdJogo.Parameters.AddWithValue("@nome", jogo.nome);
                 cmdJogo.Parameters.AddWithValue("@imagemUrl", jogo.imagemUrl);
                 cmdJogo.Parameters.AddWithValue("@id", jogo.id);
                 cmdJogo.ExecuteNonQuery();
             }
         }
     }
     catch (SystemException)
     {
         throw;
     }
 }