コード例 #1
0
        /// <summary>
        /// metodo que obtiene una lista de juegos extraida de la base de datos
        /// </summary>
        /// <returns>lista de juegos</returns>
        public List <Games> List()
        {
            using (SqlConnection sqlConnection = new SqlConnection(this.connectionString))
            {
                string     command    = "SELECT * FROM Games";
                SqlCommand sqlCommand = new SqlCommand(command, sqlConnection);
                sqlConnection.Open();
                SqlDataReader reader = sqlCommand.ExecuteReader();

                List <Games> psList = new List <Games>();

                while (reader.Read())
                {
                    int            codigo      = (int)reader["codigo"];
                    string         nombre      = (string)reader["nombre"];
                    int            precio      = (int)reader["precio"];
                    int            lanzamiento = (int)reader["lanzamiento"];
                    string         formato     = (string)reader["formato"];
                    string         plataforma  = (string)reader["plataforma"];
                    Games.EFormato formatoEnum = (Games.EFormato)Enum.Parse(typeof(Games.EFormato), formato);
                    Games          gamesPS     = new Games(precio, lanzamiento, nombre, codigo, formatoEnum, plataforma, "NO");
                    psList.Add(gamesPS);
                }
                return(psList);
            }
        }
コード例 #2
0
        private void btnCarrito_Click(object sender, EventArgs e)
        {
            string nombreJuego = txtNombre.Text;
            string modelo      = cmbModelo.Text;

            Games.EFormato formato = Games.EFormato.Fisico;
            //GamesDAO games = new GamesDAO();
            List <Games> games1 = games.Stock;

            if (radiobtnDigital.Checked)
            {
                formato = Games.EFormato.Digital;
            }
            else if (radiobtnFisico.Checked)
            {
                formato = Games.EFormato.Fisico;
            }
            foreach (Games g in games1)
            {
                if (g.Nombre == nombreJuego && g.Plataforma == modelo && g.Formato == formato)
                {
                    Games game1 = new Games(g.Precio, g.Lanzamiento, g.Nombre, g.Codigo, g.Formato, g.Plataforma);
                    games.ListaJuegos.Add(game1);

                    richTextBox1.Text = (Games.MostrarDatos(games.ListaJuegos));
                    break;
                }
            }
            if (!games.ValidarPlataforma(modelo))
            {
                MessageBox.Show("La plataforma ingresada es invalida");
            }
            if (!games.ValidarNombre(nombreJuego))
            {
                MessageBox.Show("El nombre del juego es invalido o no esta en Stock");
            }
        }