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;
using System.Collections.Specialized;
using System.Text;
using System.Configuration;
using System.Net;
using System.IO;

namespace QuintoCaminoV2.Cursos
{
    public partial class DetalleCursos : System.Web.UI.Page
    {
        public int intCurso;
        protected void Page_Load(object sender, EventArgs e)
        {
            intCurso = Convert.ToInt32(Request.QueryString["iCursoId"]);

            get_Cursos();
            getCursosTodos();
            Pay();
        }

        public void Pay()
        {
            if(!(Session["Page"] == null))
                panelPay.Visible = true;
            else
                panelPay.Visible = false;
        }

        public void getCursosTodos()
        {

            DataLayer oDataLayer = new DataLayer();
            Data_objects.Cursos oCursos = new Data_objects.Cursos();
            DataCursos.DataSource = oDataLayer.get_Cursos(oCursos);
            DataCursos.DataBind();


        }

        public void get_Cursos()
        {

            DataLayer oDataLayer = new DataLayer();
            Data_objects.Cursos oCharlas = new Data_objects.Cursos();
            List<Data_objects.Cursos> oData = oDataLayer.get_Cursos(oCharlas);
            var obj = from b in oData
                      where b.intCursoId == intCurso
                      select b;

            foreach (Data_objects.Cursos oDetalle in obj)
            {
                lblDescripcion.Text = oDetalle.vchDescripcion;
                lblCosto.Text = oDetalle.decCosto.ToString();
                lblTitulo.Text = oDetalle.vchTitulo;

            }
        }

        protected void lnkInscribir_Click(object sender, EventArgs e)
        {
            Session["Page"] = "~/Cursos/DetalleCursos.aspx?iCursoId=" + Request.QueryString["iCursoId"].ToString();
            if (Session["idUsuario"] == null)
            {
                ModalPopupExtender2.Show();
            }
            else
            {
              
            }
        }


        private static String PreparePOSTForm(string url)
        {
            ////Set a name for the form
            //string formID = "PostForm";


            ////Build the form using the specified data to be posted.
            //StringBuilder strForm = new StringBuilder();
            //strForm.Append("<form id='" + formID + "' name='" + formID + "' action='" + ConfigurationManager.AppSettings["PayPalSubmitUrl"] + "' method='POST'>");            
            //strForm.Append("<input type='hidden' name='cmd' value='_xclick' />");
            //strForm.Append("<input type='hidden' name='business' value='" + ConfigurationManager.AppSettings["PayPalUsername"] + "'/>");
            //strForm.Append("<input type='hidden' name='item_name' value='" + "Curso1" + "' />");
            //strForm.Append("<input type='hidden' name='amount' value='" + "10.00" + "' />");
            //strForm.Append("<input type='hidden' name='return' value='" + "http:\\/\\/localhost:17911/PDT/PDTSuccess.aspx" + "' />");
            //strForm.Append("<input type='hidden' name='custom' value='" + DateTime.Now.ToString() + "' />");

            //strForm.Append("</form>");

            ////Build the JavaScript which will do the Posting operation.
            //StringBuilder strScript = new StringBuilder();
            //strScript.Append("<script language='javascript'>");
            //strScript.Append("var v" + formID + " = document." + formID + ";");
            //strScript.Append("v" + formID + ".submit();");
            //strScript.Append("</script>");

            //Build the JavaScript which will do the Posting operation.
            StringBuilder strScript = new StringBuilder();
            strScript.Append("<script language='javascript'>");
            strScript.Append(" window.open('../TestHelper.aspx','popup','width=300,height=400'; ");
            strScript.Append("</script>");

            //Return the form and the script concatenated. (The order is important, Form then JavaScript)
            return strScript.ToString();
        }


        public void RedirectAndPOST(Page page, string destinationUrl)
        {
            //Prepare the Posting form
            string strForm = PreparePOSTForm(destinationUrl);

            //Add a literal control the specified page holding the Post Form, this is to submit the Posting form with the request.
            //page.Controls.Add(new LiteralControl(strForm));

            //page.Controls.Add(new LiteralControl(strForm));
            page.Controls.Add(new LiteralControl(strForm));

        }

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

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

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            //redirect();
            //RedirectAndPOST(this, "ok");
            //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "DoPostBack", "__doPostBack('', '')", true);

            string url = "../Buy/BuyPayPal.aspx?Costo=" + lblCosto.Text + "&Producto=" + lblTitulo.Text + "&IntCursoId=" + intCurso;

            string Script = @"<script type='text/javascript'>window.open('" + url + "','abc','dialogWidth:800px; dialogHeight:600px; center:yes;');</script>";
            //string Script = @"<script type='text/javascript'>function showPage(url) {newwindow=window.open(url,'name','height=200,width=150');if (window.focus) {newwindow.focus()}return false;</script>";
            ClientScript.RegisterStartupScript(this.Page.GetType(), "PreviewWindow", Script);
        }


       
    }
}