using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web.Design;
using CrystalDecisions.Web;

using System.IO;
using DL;

using System.Reflection;

public partial class rpt_AnalisisPorCuenta : System.Web.UI.Page
{
    ReportDocument reportDocument = new ReportDocument();
    ParameterField paramField = new ParameterField();
    ParameterFields paramFields = new ParameterFields();
    ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();

    string reportPath;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (String.IsNullOrEmpty(Request.QueryString["ARA"])) { ViewState["ARA"] = "0"; }
            if (String.IsNullOrEmpty(Request.QueryString["UNG"])) { ViewState["UNG"] = "0"; }

        }

    }

    private void Page_Init(object sender, EventArgs e)
    {
        btnShowReport();
    }


    protected void btnShowReport()
    {
        try
        {

            String strServidor = "";
            String strBaseDatos = "";
            String strUsuario = "";
            String strClave = "";

            reportPath = Server.MapPath(ConfigurationManager.AppSettings.Get("rptAnalisisPorCuenta"));

            if (ConfigurationSettings.AppSettings.Get("TipoConexion").ToString() == "1")
            {
                strServidor = Encriptador.Encriptador.f_desencriptar(ConfigurationSettings.AppSettings.Get("Servidor"));
                strBaseDatos = Encriptador.Encriptador.f_desencriptar(ConfigurationSettings.AppSettings.Get("BaseDatos"));
                strUsuario = Encriptador.Encriptador.f_desencriptar(ConfigurationSettings.AppSettings.Get("Usuario"));
                strClave = Encriptador.Encriptador.f_desencriptar(ConfigurationSettings.AppSettings.Get("Clave"));
            }


            reportDocument.Load(reportPath);

            reportDocument.DataSourceConnections[0].SetConnection(strServidor, strBaseDatos, strUsuario, strClave);

            //reportDocument.SetParameterValue("@EstablecimientoID", "1");
            //reportDocument.SetParameterValue("@Ejercicio", "2010");
            //reportDocument.SetParameterValue("@PlanCuentaID", "10111");
            //reportDocument.SetParameterValue("@HotelID", "0");
            //reportDocument.SetParameterValue("@FechaDesde", "01/01/2010");
            //reportDocument.SetParameterValue("@FechaHasta", "31/01/2010");
            //reportDocument.SetParameterValue("@PlanCuentaID2", "10111");
            //reportDocument.SetParameterValue("@AreaID", "0");
            //reportDocument.SetParameterValue("@UnidadNegocioID", "0");
            //reportDocument.SetParameterValue("@SubDiarioID", "0");
            //reportDocument.SetParameterValue("@MonedaID", "1");
            //reportDocument.SetParameterValue("@WhereCondition", "");
            //reportDocument.SetParameterValue("@OrderByExpression", "");

            reportDocument.SetParameterValue("@EstablecimientoID", Request.QueryString["et"]);
            reportDocument.SetParameterValue("@Ejercicio", Request.QueryString["ej"]);
            reportDocument.SetParameterValue("@PlanCuentaID", Request.QueryString["CTAID"]);
            reportDocument.SetParameterValue("@HotelID", Request.QueryString["HTL"]);
            reportDocument.SetParameterValue("@FechaDesde", Request.QueryString["FED"]);
            reportDocument.SetParameterValue("@FechaHasta", Request.QueryString["FEH"]);
            reportDocument.SetParameterValue("@PlanCuentaID2", Request.QueryString["CTAID2"]);
            reportDocument.SetParameterValue("@AreaID", ViewState["ARA"]);
            reportDocument.SetParameterValue("@UnidadNegocioID", ViewState["UNG"]);
            reportDocument.SetParameterValue("@SubDiarioID", Request.QueryString["SUD"]);
            reportDocument.SetParameterValue("@MonedaID", Request.QueryString["MON"]);
            reportDocument.SetParameterValue("@WhereCondition", Request.QueryString["Whr"]);
            reportDocument.SetParameterValue("@OrderByExpression", Request.QueryString["Ord"]);

            if (Request.QueryString["MON"].Trim() == "1")
            {
                reportDocument.SetParameterValue("@Expresado", "Soles");
            }
            else
            {
                reportDocument.SetParameterValue("@Expresado", "Dolares");
            }
            //reportDocument.SetParameterValue("@CodigoCuenta", "10111 - Caja General - Soles");

            CrystalReportViewer1.ReportSource = reportDocument;
            CrystalReportViewer1.DataBind();
        }
        catch (Exception ex)
        {
            showMessage(ex.Message);
        }
    }

    protected void showMessage(string strMessage)
    {
        String Mensaje = strMessage.Replace("'", "").Replace(",", "-").Replace("\r\n", " ");
        ScriptManager.RegisterStartupScript(this, this.GetType(), "MENSAJE", "alert('" + Mensaje + "');", true);
    }

}
