Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data.SqlClient;
- using System.Web.Configuration;
- using System.Data;
- using ENTIDADES;
- namespace DAO
- {
- public class DAOProducto
- {
- private string cadena;
- public DAOProducto()
- {
- cadena = WebConfigurationManager.ConnectionStrings["cadena"].ConnectionString;
- }
- public List<eProducto> ListarTodo()
- {
- SqlConnection con = new SqlConnection(cadena);
- SqlCommand cmd = new SqlCommand("SP_PRODUCTO_LISTAR_TODO", con);
- List<eProducto> lista = new List<eProducto>();
- con.Open();
- SqlDataReader lector = cmd.ExecuteReader();
- while (lector.Read())
- {
- eProducto p = new eProducto();
- p.IdProducto = lector.GetInt32(0);
- p.Nombre = lector.GetString(1);
- p.Precio = lector.GetDecimal(2);
- p.IdCategoria = lector.GetInt32(3);
- lista.Add(p);
- }
- con.Close();
- return lista;
- }
- public List<eProducto> ListarPorCategoria(int IdCategoria)
- {
- SqlConnection con = new SqlConnection(cadena);
- SqlCommand cmd = new SqlCommand("SP_PRODUCTO_LISTAR_TODO_POR_CATEGORIA", con);
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.Parameters.Add("@pIdCategoria", SqlDbType.Int).Value = IdCategoria;
- List<eProducto> lista = new List<eProducto>();
- con.Open();
- SqlDataReader lector = cmd.ExecuteReader();
- while (lector.Read())
- {
- eProducto p = new eProducto();
- p.IdProducto = lector.GetInt32(0);
- p.Nombre = lector.GetString(1);
- p.Precio = lector.GetDecimal(2);
- p.IdCategoria = lector.GetInt32(3);
- lista.Add(p);
- }
- con.Close();
- return lista;
- }
- public bool Actualizar(eProducto Producto)
- {
- SqlConnection con = new SqlConnection(cadena);
- SqlCommand cmd = new SqlCommand("SP_PRODUCTO_ACTUALIZAR", con);
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.Parameters.Add("@pIdProducto", SqlDbType.Int).Value = Producto.IdProducto;
- cmd.Parameters.Add("@pNombre", SqlDbType.VarChar).Value = Producto.Nombre;
- cmd.Parameters.Add("@pPrecio", SqlDbType.Decimal).Value = Producto.Precio;
- cmd.Parameters.Add("@pIdCategoria", SqlDbType.Int).Value = Producto.IdCategoria;
- con.Open();
- int exito = cmd.ExecuteNonQuery();
- con.Close();
- if (exito == 1)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public bool Grabar(eProducto Producto)
- {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment