using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QuintoCaminoV2.Data_objects;

namespace QuintoCaminoV2.Charlas
{
    public partial class DetalleCharlas : System.Web.UI.Page
    {
        public int intCharlaId = 0;
        public string vchVideo = "";
        protected void Page_Load(object sender, EventArgs e)
        {

            intCharlaId = Convert.ToInt32(Request.QueryString["IdCharla"]);

            get_Charlas();
            getCharlas2();
        }

        public void getCharlas2()
        {

            DataLayer oDataLayer = new DataLayer();
            Data_objects.Charlas oCharlas = new Data_objects.Charlas();
            List<Data_objects.Charlas> lstCharlas = new List<Data_objects.Charlas>();
            lstCharlas = oDataLayer.get_Charlas(oCharlas);


            DataCharlas.DataSource = lstCharlas.Take(3);
            DataCharlas.DataBind();

         }
        public void get_Charlas()
        {

            DataLayer oDataLayer = new DataLayer();
            Data_objects.Charlas oCharlas = new Data_objects.Charlas();
            List<Data_objects.Charlas> oData = oDataLayer.get_Charlas(oCharlas);
            var obj = from b in oData
                      where b.intCharlaId == intCharlaId
                      select b;
            string youtubeUrl = "";

            foreach (Data_objects.Charlas oDetalle in obj)
            {
                lblDescripcion.Text = oDetalle.vchDescripcionCorta;
                lblFecha.Text = oDetalle.vchFecha;
                lblTitulo.Text = oDetalle.vchTitulo;
                youtubeUrl = "http://" + oDetalle.vchUrl;

            }

            //string vCode = youtubeUrl.Substring(youtubeUrl.LastIndexOf("v=") + 2);
            string vCode = youtubeUrl;

            if (vCode.Contains("&"))
            {
                vCode = vCode.Substring(0, vCode.LastIndexOf("&"));
            }

            string sHtml = "<object width='{0}' height='{1}' " + "data='http://www.youtube.com/v/{2}&autoplay=0' codetype='application/x-shockwave-flash'>" + "<param name='movie' value='http://www.youtube.com/v/{2}&autoplay=0'></param></object>";
            string sWidth = "800px";
            string sHeight = "500px";
            divVideo.InnerHtml = String.Format(sHtml, sWidth, sHeight, vCode);

        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            string oValor;
            LinkButton obj = (LinkButton)sender;
            oValor = obj.CommandArgument;

            //DetalleCharlas oCharla = new DetalleCharlas(Convert.ToInt16(oValor));
            Response.Redirect("Charlas/DetalleCharlas.aspx?IdCharla=" + oValor);
        }
    }
}