<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="frm_buscarEmpresas.aspx.vb" Inherits="SGHweb.frm_buscarEmpresas" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            var cell_razonsocial
            var cell_empresaid
            function RadGrid_RowSelected(sender, eventArgs) {
                var grid = sender;
                var MasterTable = grid.get_masterTableView();
                var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];
                 cell_razonsocial = MasterTable.getCellByColumnUniqueName(row, "razonsocial");
                 cell_empresaid = eventArgs.getDataKeyValue("empresaid");
                 cell_razonsocial = cell_razonsocial.innerHTML;
                //alert(cell_empresaid);
                //alert(cell_razonsocial.innerHTML);
                returnToParent();
            }
            function OnKeyPress(sender, eventArgs) {
                var c = eventArgs.get_keyCode();
                if (c == 13) {
                    __doPostBack('RadButton1', '');
                }
            }
            function returnToParent() {
                //create the argument that will be returned to the parent page
                var oArg = new Object();

                //get the city's name           
                oArg.cell_razonsocial = cell_razonsocial;
                oArg.cell_empresaid = cell_empresaid;
                

                //get a reference to the current RadWindow
                var oWnd = GetRadWindow();

                //Close the RadWindow and send the argument to the parent page
                if (oArg.cell_razonsocial && oArg.cell_empresaid) {
                    oWnd.close(oArg);
                }

            }
            function GetRadWindow() {
                var oWindow = null;
                if (window.radWindow) oWindow = window.radWindow;
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
                return oWindow;
            }
        </script> 
    </telerik:RadCodeBlock>

</head>
<body>
    <form id="form1" runat="server">
    <div>
    <center>
        <telerik:RadTextBox ID="RadTextBox1" Runat="server" Skin="Windows7" 
            style="top: 0px; left: 0px">
            <ClientEvents OnKeyPress="OnKeyPress" />
        </telerik:RadTextBox>
        <br />
        <br />
        <telerik:RadButton ID="RadButton1" runat="server" Text="Buscar" Skin="Windows7">
        </telerik:RadButton>
        <br /><br />
        <telerik:RadGrid ID="RadGrid1" runat="server" Culture="es-ES" 
            DataSourceID="SqlDataSource_BuscarEmpresas" Skin="Windows7" 
            CellSpacing="0" GridLines="None" Width="500px">
            <ClientSettings>

            <Selecting CellSelectionMode="None" AllowRowSelect="True" ></Selecting>
            <ClientEvents  OnRowSelected="RadGrid_RowSelected" />

            </ClientSettings>

            <MasterTableView AutoGenerateColumns="False" DataKeyNames="empresaid" ClientDataKeyNames="empresaid"
                            DataSourceID="SqlDataSource_BuscarEmpresas" 
                NoMasterRecordsText="">
            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>

            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
            <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>

            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
            <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
                
                <Columns>
                    
                    <telerik:GridBoundColumn DataField="empresaid" DataType="System.Int32" 
                        FilterControlAltText="Filter empresaid column" HeaderText="empresaid" 
                        ReadOnly="True" SortExpression="empresaid" UniqueName="empresaid" 
                        Visible="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="razonsocial" 
                        FilterControlAltText="Filter razonsocial column" HeaderText="Empresa" 
                        SortExpression="razonsocial" UniqueName="razonsocial">
                    </telerik:GridBoundColumn>
                </Columns>

            <EditFormSettings>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
            </EditFormSettings>
            </MasterTableView>

            <FilterMenu EnableImageSprites="False"></FilterMenu>
        </telerik:RadGrid>
        <asp:SqlDataSource ID="SqlDataSource_BuscarEmpresas" runat="server" 
            SelectCommand="SELECT [empresaid], [razonsocial] FROM [empresas] WHERE ([razonsocial] LIKE '%' + @razonsocial + '%') UNION SELECT  0 AS [empresaid], 'Todas' AS [razonsocial] ORDER BY [empresaid]">
            <SelectParameters>
                <asp:ControlParameter ControlID="RadTextBox1" Name="razonsocial" 
                    PropertyName="Text" Type="String" DefaultValue="Todas"/>
            </SelectParameters>
        </asp:SqlDataSource>
    </center>
    </div>
    <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
    </telerik:RadScriptManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Runat="server" 
        Skin="Default">
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" 
        DefaultLoadingPanelID="RadAjaxLoadingPanel1">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadTextBox1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" 
                        LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadButton1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" 
                        LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    </form>
</body>
</html>
