<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="RelatorioDinamico.ascx.vb" Inherits="WebFoundations.WFReports.UI.RelatorioDinamico" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
<%@ Register TagPrefix="wff" Namespace="WebFoundations.ServerControls" Assembly="WebFoundations.ServerControls" %>

<script src="../../../wfresources/formsweb/Scripts/WFForms.Masks.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
    function OpenEditor<%= Me.ClientID %>(PortalId, FormId, AreaId, CodigoAutomatico, Page, Edit) {
        window.radopen('%%PORTAL%%WFContent/Modules/WFReports/' + Page + '?Edit=' + Edit + '&CodigoAutomatico=' + CodigoAutomatico + '&PortalID=' + PortalId + '&FormID=' + FormId + '&AreaId=' + AreaId, 'EditDialog');
        return false;
    }

    function refreshGrid() {
        var hiddenField = $get('<%= Me.hidField.ClientID %>');
        if (hiddenField) {
            hiddenField.value = (new Date()).getTime();
            document.getElementById('<%= Me.hidBusca.ClientId %>').value = 'true';
            __doPostBack('<%= Me.hidField.ClientID %>', '');
        }
    }

    function AbreModalForm<%= Me.ClientID %>(PortalId, FormId, AreaId, CodigoAutomatico, Page, Edit) {
        var Retorno = window.showModalDialog('%%PORTAL%%WFContent/Modules/WFReports/' + Page + '?Edit=' + Edit + '&CodigoAutomatico=' + CodigoAutomatico + '&PortalID=' + PortalId + '&FormID=' + FormId + '&AreaId=' + AreaId, 'Preview', 'dialogHeight: 600px; dialogWidth 500px; edge: Raised; center: Yes; help: No; resizable: Yes; status: No; scroll: Auto;');
        if (Retorno == 'Ok') {
            document.getElementById('<%= Me.hidBusca.ClientId %>').value = 'true';
        }
    }


    function Valida_Numeros() {
        var eKeyCode = GetKeyCode(event);
        if (eKeyCode < 48 || eKeyCode > 57) {
            event.returnValue = false;
        }

    }

    function Formatadata(Campo, teclapres) {
        var eKeyCode = GetKeyCode(event);
        if (eKeyCode < 48 || eKeyCode > 57) {
            event.returnValue = false;
        }

        var tecla = teclapres.keyCode || teclapres.which;
        var vr = new String(Campo.value);
        vr = vr.replace("/", "");
        vr = vr.replace("/", "");
        vr = vr.replace("/", "");
        tam = vr.length + 1;
        if (tecla != 8 && tecla != 8) {
            if (tam > 0 && tam < 2) {
                Campo.value = vr.substr(0, 2);
            }
            if (tam > 2 && tam < 4) {
                Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2);
            }
            if (tam > 4 && tam < 7) {
                Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2) + '/' + vr.substr(4, 7);
            }
        }
    }


    function displayDiv() {
        var divstyle = new String();
        divstyle = document.getElementById("div1").style.display;
        if (divstyle.toLowerCase() == 'none' || divstyle == '') {
            document.getElementById("div1").style.display = 'block';
            document.getElementById("btnErro").value = 'Ocultar Erro';

        }
        else {
            document.getElementById("div1").style.display = 'none';
            document.getElementById("btnErro").value = 'Exibir Erro';
        }
    }

    (function () {
        //função para arrumar o colspan da paginação do reports devido a um bug no DataGrid quando usa colunas automáticas a partir do .NET 2
        var fixReportPagerColspan = function () {
            if ($("table.wfreport").has("tr.pager")) {
                var span = 3;
                $("table.wfreport tr").each(function () {
                    span = Math.max(span, $("td", this).length);
                });
                $("tr.pager td").attr("colspan", span);
            }
        };

        if ($) {
            try {
                $(document).ready(function () {
                    fixReportPagerColspan();
                });
            } catch (error) { }
        }
    })();
</script>
<input id="hidBusca" type="hidden" name="hidBusca" runat="server" />
<asp:Label ID="lblFormID" Visible="False" runat="server" />

<h2 class="wfreport-header">
    <asp:Label ID="lblNomeForm" runat="server" />
    <asp:Label ID="lblNomeTabela" runat="server" Visible="False" />
    <asp:Label ID="lblInvisiveis" runat="server" Visible="False" />
    <asp:Label ID="lblTipoRelatorio" runat="server" Visible="False" Text="0" />
</h2>

<asp:Panel ID="pnlSearchBox" DefaultButton="btnBusca" runat="server" CssClass="wfreport-search wfrep-part">
    <asp:PlaceHolder ID="phRelatorioDinamico" runat="server" EnableViewState="True" />
    <asp:Button ID="btnBusca" runat="server" Text="btnBusca" />
</asp:Panel>

<asp:Panel ID="pnlErro" runat="server" Visible="false" CssClass="wfreport-error wfrep-part">
    <asp:Label ID="lblErro" runat="server"></asp:Label><p />
</asp:Panel>

<asp:Panel ID="pnlErrosDetalhes" runat="server" Visible="false" CssClass="wfreport-error-details wfrep-part">
    <input id="btnErro" type="button" value="Exibir Erro" onclick="displayDiv();" />
    <div id="div1" class="divStyle" style="display: none; width: 100%; margin: 0px auto;">
        <asp:Label ID="lblErrorDetalhes" runat="server"></asp:Label>
    </div>
</asp:Panel>

<asp:Panel ID="pnlReport" runat="server" CssClass="wfreport-chart wfrep-part" visible="False">
    <telerik:RadHtmlChart runat="server" ID="chtRelatorio" Visible="true">
        <ChartTitle>
            <Appearance Position="Top" />
        </ChartTitle>
        <PlotArea>
            <XAxis>
                <MinorGridLines Visible="false" />
                <MajorGridLines Visible="false" />
            </XAxis>
            <YAxis>
                <MinorGridLines Visible="false" />
            </YAxis>
        </PlotArea>
    </telerik:RadHtmlChart>
</asp:Panel>

<asp:DataGrid ID="dtgRelatorio" runat="server" CssClass="wfreport results wfrep-part" GridLines="None" UseAccessibleHeader="true" BorderStyle="NotSet" AllowPaging="True">
    <Columns>
        <asp:TemplateColumn>
            <ItemStyle HorizontalAlign="Center" Width="18px" />
            <ItemTemplate>
                <asp:LinkButton ID="ibtnExcluir" CommandName="Excluir" runat="server"><img src="%%PORTAL%%WFResources/Common/Images/Icons/delete.png" border="0"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateColumn>
        <asp:TemplateColumn>
            <ItemStyle HorizontalAlign="Center" Width="18px" />
            <ItemTemplate>
                <asp:LinkButton ID="ibtnEditar" CommandName="Editar" runat="server"><img src="%%PORTAL%%WFResources/Common/Images/Icons/edit.png" border="0"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateColumn>
        <asp:TemplateColumn>
            <ItemStyle HorizontalAlign="Center" Width="18px" />
            <ItemTemplate>
                <asp:LinkButton ID="ibtnPreview" CommandName="Preview" runat="server"><img src="%%PORTAL%%WFResources/Common/Images/icons/view.png" border="0"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateColumn>
    </Columns>
    <PagerStyle Mode="NumericPages" CssClass="pager" />
</asp:DataGrid>

<wff:WindowManager ID="EditWindow" runat="server">
    <Windows>
        <telerik:RadWindow ID="EditDialog" runat="server" Height="600px" Width="700px" ReloadOnShow="false" Modal="true" />
    </Windows>
</wff:WindowManager>
<asp:HiddenField ID="hidField" runat="server" />

<section class="wfreport-actions actions wfrep-part">
    <asp:Button CausesValidation="false" CssClass="wfreport-action txt" ID="btnGerartxt" runat="server" />
    <asp:Button CausesValidation="false" CssClass="wfreport-action csv" ID="btnGerarcsv" runat="server" />
    <asp:Button CausesValidation="false" CssClass="wfreport-action xls" ID="btnGerarexcel" runat="server" />
</section>
