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.Data;

namespace QuintoCaminoV2.Admin
{
    public partial class AdminPagos : System.Web.UI.Page
    {
        DataTable dt;


        protected void Page_Load(object sender, EventArgs e)
        {
            //SavePagos();
            getPagos();
        }


        public void getPagos()
        {
            DataLayer oDataLayer = new DataLayer();
            Data_objects.Pagos oCharlas = new Data_objects.Pagos();
            grdPagos.DataSource = oDataLayer.get_AllPagos();
            grdPagos.DataBind();
        }

        public void SavePagos()
        {
            List<Data_objects.Pagos> lstPagos = new List<Data_objects.Pagos>();
            Data_objects.Pagos oPago = new Data_objects.Pagos();
            DataLayer oDataLayer = new DataLayer();
            Errores oError = new Errores();


            oPago.vchUsuario      = "makrack";		
            oPago.intUsuarioId	= 1;
            oPago.vchFolioPayPal	= "123456";
            oPago.decMontoPago	= 2000;
            oPago.intCursoId		= 1;
            oPago.bitConfirmado	= false;
            oPago.datFechaPago	= DateTime.Today.ToString();
            oPago.datFechaAlta = DateTime.Today.ToString();
            oPago.vchEstatusPago	= "CONFIRMADO";
            oPago.bitActivo		= true;
            oPago.vchMetodoPago = "PAYPAL";
            oPago.vchCurso = "Curso 1";

            lstPagos.Add(oPago);

            oError = oDataLayer.insertPago(lstPagos);

            if (!(oError.bitError))
            {

            }

        }

        protected void grdPagos_RowCommand(object sender, GridViewCommandEventArgs e)
        {
          if(e.CommandName.Equals("detail"))

          {

              int index = Convert.ToInt32(e.CommandArgument);

              int code = Convert.ToInt32(grdPagos.DataKeys[index].Value);
              List<Pagos> oPagos = (List<Pagos>)grdPagos.DataSource;

              IEnumerable<Pagos> query = from i in oPagos
                           where i.intPagoID.Equals(code)
                           select i;


              foreach(Pagos pag in query)
              {
                  txtCursoID.Value = pag.intCursoId.ToString();
                  txtPagoID.Value = pag.intPagoID.ToString();
                  txtUsuario.Value = pag.intUsuarioId.ToString();
              }
               // int index = Convert.ToInt32(e.CommandArgument);             


                  System.Text.StringBuilder sb = new System.Text.StringBuilder();
                  sb.Append(@"<script type='text/javascript'>");
                  sb.Append("$('#modalConfirmar').modal('show');");
                  sb.Append(@"</script>");
                  ScriptManager.RegisterClientScriptBlock(this, this.GetType(),"ModalScript", sb.ToString(), false);
            }

        }

        [System.Web.Services.WebMethod]
        public static void Confirma(string txtPagoID, string txtCursoID, string txtUsuario)
        {


        }


        [System.Web.Services.WebMethod]
        public static void ConfirmaPago(string txtPagoID, string txtCursoID, string txtUsuario)
        {
            List<Data_objects.Pagos> lstPagos = new List<Data_objects.Pagos>();
            Data_objects.Pagos oPago = new Data_objects.Pagos();
            DataLayer oDataLayer = new DataLayer();
            Errores oError = new Errores();

            oPago.intCursoId = Convert.ToInt32(txtCursoID);
            oPago.intPagoID = Convert.ToInt32(txtPagoID);
            oPago.intUsuarioId = Convert.ToInt32(txtUsuario);

            lstPagos.Add(oPago);

            oError = oDataLayer.ConfirmPago(lstPagos);

            if (!(oError.bitError))
            {

            }


            
            

        }


    }
}