示例#1
0
        public static List <Alumno> TraerTodos(string ciudad)
        {
            string     procedure = "TraerTodosPorCiudad";
            SqlCommand command   = new SqlCommand(procedure, AdminDB.ConectarDB());

            //definir tipo de comando
            command.CommandType = CommandType.StoredProcedure;
            //definir parametro
            command.Parameters.Add("@ciudad", SqlDbType.VarChar, 50).Value = ciudad;
            SqlDataReader reader = command.ExecuteReader();
            List <Alumno> lista  = new List <Alumno>();

            while (reader.Read())
            {
                lista.Add(new Alumno(
                              reader["Nombre"].ToString(),
                              reader["Apellido"].ToString(),
                              int.Parse(reader["DNI"].ToString()),
                              reader["Email"].ToString(),
                              reader["Ciudad"].ToString(),
                              int.Parse(reader["NroLegajo"].ToString())
                              ));
            }
            AdminDB.CerrarConexion();
            return(lista);
        }
        public static int CmdInsert(Producto producto)
        {
            string query = "INSERT INTO dbo.Productos (Nombre ,Precio ,IdCategoria) VALUES (@Nombre, @Precio, @IdCategoria); SELECT SCOPE_IDENTITY()";

            SqlCommand command = new SqlCommand(query, AdminDB.ConectarDB());

            command.Parameters.Add("@Nombre", SqlDbType.VarChar, 50).Value = producto.Nombre;
            command.Parameters.Add("@Precio", SqlDbType.Money).Value       = producto.Precio;
            command.Parameters.Add("@IdCategoria", SqlDbType.Int).Value    = producto.IdCategoria;


            object filasAfectadas = command.ExecuteScalar(); //Invocar: inser into-update-delete

            //Cerrar connecion de la DB
            AdminDB.ConectarDB().Close();

            if (filasAfectadas != null)
            {
                return(Convert.ToInt32(filasAfectadas));
            }
            else
            {
                return(0);
            }
        }
示例#3
0
        public static List <Alumno> TraerTodos()
        {
            //1 connection
            //2 sql o spu
            string query = "SELECT [Id],[Nombre],[Apellido],[DNI],[Email],[Ciudad],[NroLegajo]FROM[dbo].[Alumno]";
            //3 comando SqlCommand
            SqlCommand command = new SqlCommand(query, AdminDB.ConectarDB());
            //4 objeto reader
            //5 invcocar SqlCommand y trabajar con el reader
            SqlDataReader reader = command.ExecuteReader();
            //6 crear la lista
            List <Alumno> lista = new List <Alumno>();

            while (reader.Read())
            {
                lista.Add(new Alumno(
                              reader["Nombre"].ToString(),
                              reader["Apellido"].ToString(),
                              int.Parse(reader["DNI"].ToString()),
                              reader["Email"].ToString(),
                              reader["Ciudad"].ToString(),
                              int.Parse(reader["NroLegajo"].ToString())
                              ));
            }
            AdminDB.CerrarConexion();
            return(lista);
        }
示例#4
0
        public static int Eliminar(int idAlumno)
        {
            string     query    = "DeleteAlumnoPorId";
            SqlCommand dmlQuery = new SqlCommand(query, AdminDB.ConectarDB());

            dmlQuery.CommandType = CommandType.StoredProcedure;
            dmlQuery.Parameters.Add("@Id", SqlDbType.Int).Value = idAlumno;
            return(dmlQuery.ExecuteNonQuery());
        }
示例#5
0
        public static int Agregar(Alumno alumno)
        {
            string     query    = "INSERT INTO Alumno(Nombre, Apellido, DNI, Email, Ciudad, NroLegajo)VALUES(@Nombre, @Apellido, @DNI, @Email, @Ciudad, @NroLegajo)";
            SqlCommand dmlQuery = new SqlCommand(query, AdminDB.ConectarDB());

            dmlQuery.Parameters.Add("@Nombre", SqlDbType.VarChar, 50).Value   = alumno.Nombre;
            dmlQuery.Parameters.Add("@Apellido", SqlDbType.VarChar, 50).Value = alumno.Apellido;
            dmlQuery.Parameters.Add("@DNI", SqlDbType.Char, 11).Value         = alumno.DNI;
            dmlQuery.Parameters.Add("@Email", SqlDbType.VarChar, 50).Value    = alumno.Email;
            dmlQuery.Parameters.Add("@Ciudad", SqlDbType.VarChar, 50).Value   = alumno.Ciudad;
            dmlQuery.Parameters.Add("@NroLegajo", SqlDbType.Int).Value        = alumno.NroLegajo;
            return(dmlQuery.ExecuteNonQuery());
        }
示例#6
0
        public static int Modificar(Alumno alumno)
        {
            string     query    = "UPDATE Alumno SET Nombre = @Nombre, Apellido = @Apellido, Dni = @Dni, Ciudad = @Ciudad, Email = @Email, NroLegajo = @NroLegajo WHERE ID = @Id";
            SqlCommand dmlQuery = new SqlCommand(query, AdminDB.ConectarDB());

            dmlQuery.Parameters.Add("@Nombre", SqlDbType.VarChar, 50).Value   = alumno.Nombre;
            dmlQuery.Parameters.Add("@Apellido", SqlDbType.VarChar, 50).Value = alumno.Apellido;
            dmlQuery.Parameters.Add("@Dni", SqlDbType.Char, 11).Value         = alumno.DNI;
            dmlQuery.Parameters.Add("@Email", SqlDbType.VarChar, 50).Value    = alumno.Email;
            dmlQuery.Parameters.Add("@Ciudad", SqlDbType.VarChar, 50).Value   = alumno.Ciudad;
            dmlQuery.Parameters.Add("@NroLegajo", SqlDbType.Int).Value        = alumno.NroLegajo;
            dmlQuery.Parameters.Add("@Id", SqlDbType.Int).Value = alumno.Id;
            return(dmlQuery.ExecuteNonQuery());
        }
示例#7
0
        public static int Eliminar(int pId)
        {
            string consulta = "DELETE FROM dbo.Categoria WHERE Id=@Id";

            comando = new SqlCommand(consulta, AdminDB.ConectarDB());

            comando.Parameters.Add("@Id", System.Data.SqlDbType.Int).Value = pId;

            int filasAfectadas = comando.ExecuteNonQuery();

            AdminDB.ConectarDB().Close();

            return(filasAfectadas);
        }
示例#8
0
        public static int Agregar(Categoria nuevo)
        {
            string consulta = "INSERT INTO dbo.Categoria (Nombre,Descripcion) VALUES (@Nombre, @Descripcion)";

            comando = new SqlCommand(consulta, AdminDB.ConectarDB());

            comando.Parameters.Add("@Nombre", System.Data.SqlDbType.VarChar, 50).Value      = nuevo.Nombre;
            comando.Parameters.Add("@Descripcion", System.Data.SqlDbType.VarChar, 50).Value = nuevo.Descripcion;

            int filasAfectadas = comando.ExecuteNonQuery();

            AdminDB.ConectarDB().Close();

            return(filasAfectadas);
        }
示例#9
0
        public static int Modificar(Categoria categoria)
        {
            string consulta = "UPDATE dbo.Categoria SET Nombre = @Nombre ,Descripcion = @Descripcion WHERE Id= @Id";

            comando = new SqlCommand(consulta, AdminDB.ConectarDB());

            comando.Parameters.Add("@Nombre", System.Data.SqlDbType.VarChar, 50).Value       = categoria.Nombre;
            comando.Parameters.Add("@Descripcion", System.Data.SqlDbType.VarChar, 150).Value = categoria.Descripcion;
            comando.Parameters.Add("@Id", System.Data.SqlDbType.Int).Value = categoria.Id;

            int filasAfectadas = comando.ExecuteNonQuery();

            AdminDB.ConectarDB().Close();

            return(filasAfectadas);
        }
示例#10
0
        public static int Agregar(Producto nuevo)
        {
            string consulta = "INSERT INTO dbo.Producto (Nombre,Color,Precio) VALUES (@Nombre, @Color, @Precio)";

            comando = new SqlCommand(consulta, AdminDB.ConectarDB());

            comando.Parameters.Add("@Nombre", System.Data.SqlDbType.VarChar, 50).Value = nuevo.Nombre;
            comando.Parameters.Add("@Color", System.Data.SqlDbType.VarChar, 50).Value  = nuevo.Color;
            comando.Parameters.Add("@Precio", System.Data.SqlDbType.Money).Value       = nuevo.Precio;

            int filasAfectadas = comando.ExecuteNonQuery();

            AdminDB.ConectarDB().Close();

            return(filasAfectadas);
        }
示例#11
0
        public static int Modificar(Producto producto)
        {
            string consulta = "UPDATE [dbo].[Producto] SET Nombre = @Nombre ,Color = @Color ,Precio = @Precio WHERE Id= @Id";

            comando = new SqlCommand(consulta, AdminDB.ConectarDB());

            comando.Parameters.Add("@Nombre", System.Data.SqlDbType.VarChar, 50).Value = producto.Nombre;
            comando.Parameters.Add("@Color", System.Data.SqlDbType.VarChar, 50).Value  = producto.Color;
            comando.Parameters.Add("@Precio", System.Data.SqlDbType.Money).Value       = producto.Precio;
            comando.Parameters.Add("@Id", System.Data.SqlDbType.Int).Value             = producto.Id;

            int filasAfectadas = comando.ExecuteNonQuery();

            AdminDB.ConectarDB().Close();

            return(filasAfectadas);
        }
示例#12
0
        public static List <Categoria> CmdSelect()
        {
            DataSet        ds      = new DataSet();
            string         query   = "SELECT Id,Nombre FROM dbo.Categoria";
            SqlDataAdapter adapter = new SqlDataAdapter(query, AdminDB.ConectarDB());

            adapter.Fill(ds, "Categoria");

            List <Categoria> lista = new List <Categoria>();

            foreach (DataRow auxCategoria in ds.Tables["Categoria"].Rows)
            {
                lista.Add(new Categoria(auxCategoria["Nombre"].ToString(), Convert.ToInt32(auxCategoria["Id"])));
            }

            return(lista);
        }
示例#13
0
        public static List <Producto> CmdSelect()
        {
            DataSet        ds      = new DataSet();
            string         query   = "SELECT Id,Nombre,Precio,IdCategoria FROM dbo.Productos";
            SqlDataAdapter adapter = new SqlDataAdapter(query, AdminDB.ConectarDB());

            adapter.Fill(ds, "Productos");

            List <Producto> lista = new List <Producto>();

            foreach (DataRow auxProducto in ds.Tables["Productos"].Rows)
            {
                lista.Add(new Producto(auxProducto["Nombre"].ToString(), Convert.ToDecimal(auxProducto["Precio"]), Convert.ToInt32(auxProducto["IdCategoria"]), Convert.ToInt32(auxProducto["Id"])));
            }

            return(lista);
        }